[Haskell-beginners] Value from Monad

Marcin Mrotek marcin.jan.mrotek at gmail.com
Wed Apr 22 20:23:36 UTC 2015


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


More information about the Beginners mailing list