[Haskell-beginners] [Haskell-Beginners] Just
Michael Xavier
nemesisdesign at gmail.com
Tue Jun 14 17:16:12 CEST 2011
I'm someone will offer a much more eloquent answer after me but here's my
shot as a fellow beginner:
The type Maybe is defined:
data Maybe a = Just a | Nothing
It means that a value of type Maybe String can manifest in 1 of 2 values:
either Nothing, which typically signifies an error has occurred or a "null"
value that you'd see in other programming languages.
Just "foo" is a value that represent a value that is *not* nothing, such as
a successful result from a computation. You can pattern match to get the
value out of it:
case somethingThatProducesAMaybe of
Just success -> doStuff success
Nothing -> error "Oh the humanity!"
I hope that helps.
--
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110614/c1084a44/attachment.htm>
More information about the Beginners
mailing list