[Haskell-beginners] Value from Monad

Alex Hammel ahammel87 at gmail.com
Wed Apr 22 20:37:39 UTC 2015


> Even if you're sure it's not a Nothing, it might be better to use
>
> maybe (error "Impossible, because (...)") id

Which is the same thing as:

fromMaybe (error "Impossible, because (...)")

On Wed, Apr 22, 2015 at 1:23 PM, Marcin Mrotek <marcin.jan.mrotek at gmail.com>
wrote:

> Hello,
>
> Well, you CAN use fromJust, but bear in mind that you should only use
> it if you are absolutely, positively, 100% sure the Maybe value you
> are calling fromJust on is of the form (Just something), because your
> program will error out if you call fromJust on a Nothing. Even if
> you're sure it's not a Nothing, it might be better to use
>
> maybe (error "Impossible, because (...)") id
>
> instead, so that you at the very least get a meaningful error message
> in case "impossible" happens ;) Other than that, it's recomennded to
> either use the maybe function, or pattern matching:
>
> case foo of
>   Just x -> ...
>   Nothing -> ...
>
> instead.
>
> Best regards,
> Marcin Mrotek
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150422/41f6ab8a/attachment.html>


More information about the Beginners mailing list