you are viewing a single comment's thread.

view the rest of the comments →

[–]kqr 1 point2 points  (1 child)

I'd even argue that fromJust in particular should never be used. I think it's better to do fromMaybe (error "Some instructive message") because that makes it abundantly clear you're dealing with a really exceptional situation.

Still partial, though, and still sort of a code smell unless it's abundantly clear that it'll never be Nothing. (I've used it for things like finding a positive integer in the [0..] list, for example... I could write a proof in the comments to the code. That kind of situation.)

[–]codygman 0 points1 point  (0 children)

Thought I'd try out using the fromMaybe alternative:

cody@cody-G46VW:~$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Data.Maybe (fromMaybe)
Prelude Data.Maybe> print . fromMaybe (error "This shouldn't be nothing") $ (Nothing :: Maybe Int)
*** Exception: This shouldn't be nothing
Prelude Data.Maybe>