The function fromJustin Data.Maybeis defined as follows:
fromJust :: Maybe a -> a
fromJust Nothing = error "Maybe.fromJust: Nothing"
fromJust (Just x) = x
According to my understanding of pattern matching (matching happens from top to bottom) I would change the order of the two definitions. Since usually the Nothing-part does not match in the it-is-sure-a-Just situation, but is always checked before the second definition is reached.
Can you clarify my mistake in reasoning? Thank.
Edit:
Example: Suppose I have a file with a million type numbers Intper line, and I need these numbers (like Int, not String) in my program for other things.
import qualified Data.ByteString.Lazy.Char8 as L
readInt = fst . fromJust . L.readInt
-- more stuff
With the above definition, fromJustit will take me more time to read the numbers, right?