我有一个初级 haskell 问题。
今年我用代码降临来学习Haskell。在学习first problem时,我需要将字符串转换为整数。
这是我的代码:
import Data.List.Split
import System.IO
main = do
input <- getContents
let bags = splitWhen (=="") $ lines input
let bagsInteger = map (\arr -> map (\x -> read x :: Integer)) bags :: [[Integer]]
let totals = map (sum) bagsInteger
putStrLn $ show $ maximum totals
当运行ghc
时,我得到
azl@Alains-MacBook-Air aoc-2022 % ghc 1.hs
Loaded package environment from /Users/azl/.ghc/aarch64-darwin-9.2.5/environments/default
[1 of 1] Compiling Main ( 1.hs, 1.o )
1.hs:7:36: error:
• Couldn't match expected type: [Integer]
with actual type: [String] -> [Integer]
• Probable cause: ‘map’ is applied to too few arguments
In the expression: map (\ x -> read x :: Integer)
In the first argument of ‘map’, namely
‘(\ arr -> map (\ x -> read x :: Integer))’
In the expression:
map (\ arr -> map (\ x -> read x :: Integer)) bags :: [[Integer]]
|
7 | let bagsInteger = map (\arr -> map (\x -> read x :: Integer)) bags :: [[Integer]]
任何帮助都是感激不尽的!
1条答案
按热度按时间xqkwcwgp1#
你忘了
arr
!