[Haskell-beginners] how to skip pattern match error when applying a mapM_

jean verdier verdier.jean at gmail.com
Tue Jan 17 18:17:10 UTC 2017


Just x <- y 
is a construction similar to 
let Just x = y
which is the same as
x = case y of
      Just z -> z
      Nothing -> error "pattern match failed"
Some matches are mapped to errors but not explicitly.
Just x = y 
avoid some boilerplate at the cost of hiding the non exhaustive matches
that may raise unexpected errors.
Just x <- y
is the same as 
z <- y
let x = case z of ...


On Tue, 2017-01-17 at 17:34 +0000, PICCA Frederic-Emmanuel wrote:
> > 
> >     Just gamma <- get_position' (h5gamma d) 0
> >     Just delta <- get_position' (h5delta d) idx
> >     Just wavelength <- get_position' (h5wavelength d) 0
> 
> > 
> > is asking for a trouble down the road. Use a case to pattern match
> > on nothing, (or `maybe`, or LambdaCase if you are into extensions).
> 
> I tought that was the purpose of the Monad to avoid writting these
> boillerplate ?
> 
> What I am missing ?
> 
> Cheers
> 
> Frederic
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


More information about the Beginners mailing list