[Haskell-beginners] [Haskell-Beginners] Just
Ertugrul Soeylemez
es at ertes.de
Tue Jun 14 18:20:05 CEST 2011
KC <kc1956 at gmail.com> wrote:
> > From a more technical point of view, what 'Just' does is wrapping
> > data. Whenever you see 'Just', keep in mind you're looking at a
> > data constructor.
>
> Would it be more correct to say that "Just" wraps a pure value?
That would be misleading. First of all, think in terms of Maybe, not in
terms of Just. "Just 3" is a value of type Maybe Integer just like
"True" is a value of type Bool. There is really nothing special about
it. Think of Maybe as a list type, which can contain at most one
element. In that sense [] corresponds Nothing and [3] corresponds to
Just 3. You can pattern-match against both of them in the same way:
case maybeValue of
Nothing -> "We got nothing."
Just _ -> "We got a value."
case listValue of
[] -> "We got nothing."
[_] -> "We got one value."
[_,_] -> "We got two values."
_ -> "We got more than two values."
So why is it misleading? Because (not considering that everything is
pure in Haskell) there is nothing impure about Maybe.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Beginners
mailing list