[Haskell-beginners] having trouble with helloworld style program

Ertugrul Soeylemez es at ertes.de
Mon Aug 8 18:40:41 CEST 2011


David Place <d at vidplace.com> wrote:

> >> main =do
> >>   x<-getLine
> >>   y<-return x
> >>   print $ stringToInt y
> >
> > This is exactly equivalent to the other methods, but has the
> > additional 'return', which is a no-op.  Please do not suggest such a
> > style.
>
> Really?  Without the return it will not work. So, it isn't a noop.
> Stylistically, I like it better than the 'let' in 'do' notation.

It will not work, because you have additional identifiers.  The code

    y <- return x

really just states the same as:

    let y = x

and this is a requirement of the monad laws:

    c >=> return = c
    return >=> c = c

Abusing 'return' is mostly an artifact from former imperative
programmers, who think that 'return' in Haskell is a control construct.
It's not; it's just a function.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





More information about the Beginners mailing list