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
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
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.
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