1

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
0

3 Answers 3

5

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
Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.