Map.lookup in 6.4.1

Jens Fisseler jens.fisseler at FernUni-Hagen.de
Thu Aug 10 06:21:32 EDT 2006


Hi Serge,

> Prelude> Data.Map.singleton 'a' 'b'
> {'a':='b'}
> 
> Prelude> Data.Map.lookup 'a' $ Data.Map.singleton 'a' 'b'
> 
> Prelude>
> -------------------------------
> 
> Must not it print  Just 'b'  instead of printing emptyness? 
> Further:
> 
> ----------
> Prelude> Data.Map.lookup 'b' $ Data.Map.singleton 'a' 'b'
> 
> *** Exception: user error (Data.Map.lookup: Key not found)
> ----------
> 
> Instead, must not it print  Nothing  ?

'Data.Map.lookup' has the return type 'm a', that is returns the value
within an arbitrary monad of type m, which need not even be a member of
the class 'Show'. You need to further specify the type of the monad.
'(Data.Map.lookup 'a' $ Data.Map.singleton 'a' 'b')::Maybe Char' does
what you expect.

Regards,

	Jens


More information about the Glasgow-haskell-users mailing list