[Haskell-beginners] Understanding Haskell Map.lookup Example in LYH

Francesco Ariis fa-ml at ariis.it
Mon Dec 14 12:42:34 UTC 2015


On Mon, Dec 14, 2015 at 12:36:49PM +0000, Olumide wrote:
> Hello Haskellers!
> 
> I'd appreciate help understanding the origin of the extra 'map' in
> 'Map.lookup lockerNumber map', from the following example taken from chapter
> 8 of "Learn You a Haskell for Great Good"
> http://learnyouahaskell.com/making-our-own-types-and-typeclasses#type-synonyms
> 
> lockerLookup :: Int -> LockerMap -> Either String Code
> lockerLookup lockerNumber map =
>     case Map.lookup lockerNumber map of
>         Nothing -> [...]

Hello Olumide,
  `map` is just a parameter name. `Map.lookup` type is

     λ> :t Data.Map.lookup
     Data.Map.lookup :: Ord k => k -> Map k a -> Maybe a

(so a key and a container, returning `Maybe a`). The name `map` for the
second parameter is unfortunate because it is the same as the much
loved `map` function; in this case map-the-function get shadowed by
the-parameter-named-map.

I hope this helps, if not fire again!



More information about the Beginners mailing list