[Haskell-beginners] help using Data.Map lookup - how to get values after the "Just" constructor

Daniel Fischer daniel.is.fischer at web.de
Tue Sep 21 10:18:12 EDT 2010


On Tuesday 21 September 2010 15:50:46, Martin Tomko wrote:
> Thank you Edgar, Daniel,
> these helped a lot!
> one more question regarding the suggestion of daniel, using ! if I KNOW
> that the key will occur (and as I work in a closed world, it should be
> the case).
>
> Out of curiosity - how does one use ! ??
>
> let's say I have a function returning a map: myFunct a b, and I was
> using:
>
> M.lookup c (myFunct a b)
>
> On this, I could happily use fromJust (M.lookup c (myFunct a b))
>
> Now, if I do
>
> (myFunct a b) ! c i get ! not in scope.
>
> ! seems to come from Data.Map and I import it as
> import qualified Data.Map as M
>
> I don't think I can do M.!   :))).

Too ugly?

> How to go about it?

You'd use

myFunct a b M.! c

if you have

import qualified Data.Map as M

at the top of your module.
However, qualified operators are often ugly, so I suggest

import qualified Data.Map as M
import Data.Map (Map, (!))
-- to get the type name and the (!) operator for unqualified use

myFunct a b ! c

or, with parentheses,

(myFunct a b) ! c



More information about the Beginners mailing list