Data.Map类型声明

时间:2012-02-24 08:37:56

标签: haskell

import Data.Map as Map

test :: Int -> Int -> Map -> Map
test key value cache = Map.insert key value cache

错误:

`Map' is not applied to enough type arguments
Expected kind `??', but `Map' has kind `* -> * -> *'
In the type signature for `test': test :: Int -> Int -> Map -> Map

如何声明函数将Data.Map作为参数传递?

1 个答案:

答案 0 :(得分:7)

你必须说明的地图

test :: Int -> Int -> Map Int Int -> Map Int Int
test key value cache = Map.insert key value cache

您的密钥为Int s,您存储的值也为Int s,因此您的地图的类型为Map Int Int

如果密钥为String且值为Bool s,则地图的类型为Map String Bool