开发者

haskell pass map in parameter

how can I pass a Data.Map mapping Int to [Char] in haskell? How do th开发者_开发百科e function header looks like? Let's assume that the function will return an int

import qualified Data.Map as M
someFunction :: <insert your answer here> -> Int


A working and compilable example:

module Foo where
import qualified Data.Map as M
mapSize :: M.Map Int [Char] -> Int
mapSize m = M.size m

which lets you do things, say in GHCi, like

*Foo> let m = M.fromList [(2,"abc"), (3,"cde")] :: M.Map Int [Char]
*Foo> mapSize m
2


It depends on how you import Data.Map. If you import Data.Map unqualified (you most likely don't, this is why I choose it as example ;) ), it would be Map Int [Char]. How do I know? Simple, documentation says:

data Map k a

A Map from keys k to values a.


Well, const 5 :: Map Int [Char] -> Int, for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜