我不知道如何同时导入两个不同的模块。以下代码
import qualified Data.Map as Map
import Data.List
phoneBookToList :: (Ord k) => [(k,String)] -> Map.Map k String
phoneBookToList xs = Map.fromListWith (\n1 n2 -> n1 ++ ", " ++ n2) xs
phoneBookFromWithList :: (Ord k) => [(k,a)] -> Map k [a]
phoneBookFromWithList = Map.fromListWith (++) $ map (\(k,a) -> (k,[a]))
抛出此错误
Not in scope: type constructor or class `Map'
Perhaps you meant `Map.Map' (imported from Data.Map)
Failed, modules loaded: none.
map (\(k,a) -> (k,[a]))
我试图从默认的Prelude模块中使用它。我试过Data.List.map (\(k,a) -> (k,[a]))
,但仍然出错。它虽然是一个GHCi命令。提前致谢
答案 0 :(得分:2)
您要导入Data.Map
限定为Map
,但尝试在没有资格的情况下参考Map
数据类型。
您需要将Map k [a]
的类型签名中的phoneBookFromWithList
更改为Map.Map k [a]
才能正确引用Map
数据类型。