【发布时间】:2017-02-26 21:37:06
【问题描述】:
我是 Haskell 的新手,下面的代码给了我两个错误:
import Control.Monad
import Control.Applicative
import System.IO
import qualified Data.Map as Map
import Data.Maybe
main = do
return ()
getPhonebook :: Int -> (Map.Map String String)
getPhonebook n
| n == 0 = Map.empty
| otherwise = do
line <- getLine
let split = words line
return (Map.insert (split !! 0) (split !! 1) (getPhonebook (n-1)))
第一个错误在line <- getLine 行。错误显示Couldn't match type ‘IO’ with ‘Map.Map String’。我不明白这个错误,可能是一个愚蠢的错误。
第二个错误在返回线上。它说Couldn't match type ‘Map.Map String String’ with ‘[Char]’,预期的类型是[Char]。我不明白这一点,因为该函数应该返回一个地图,但它要求[Char]。
任何帮助将不胜感激:D
【问题讨论】: