tags:

views:

110

answers:

3

hi, how can I pass a Data.Map mapping Int to [Char] in haskell? How do the 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
+1  A: 

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.

delnan
cool, and could you please provide some example with qualified import?
coubeatczech
@coubeatczech: Oh come on, is it *that* hard? Common sense should be able to tell you the answer from here...
delnan
+1  A: 

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

kohomologie
+5  A: 

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
Mikael Vejdemo-Johansson