[Haskell-beginners] having trouble with helloworld style program

Hartmut hartmut0407 at googlemail.com
Mon Aug 8 13:54:55 CEST 2011


here...

<-    is good for "pulling out" a result/value out of an IO Action (after
running it)
let    is good for the assignment of a pure functional evaluation/result

Hope this is roughly correct :-)
Hartmut

On Mon, Aug 8, 2011 at 1:45 PM, Ertugrul Soeylemez <es at ertes.de> wrote:

> Sunil S Nandihalli <sunil.nandihalli at gmail.com> wrote:
>
> > module Main where
> > import Prelude
> >
> > stringToInt::String->Int
> > stringToInt str = read str
> >
> > main =
> >     do x<-getLine
> >        y<-stringToInt x
> >        print y
>
> It is a type problem.  Using the '<-' syntax for 'stringToInt' requires
> that it is a monadic function (like: String -> IO Int), but it is not.
> Since it is not monadic, you can simply let-bind the result to a name:
>
>    do xStr <- getLine
>       let x = stringToInt xStr
>       print x
>
> Or more simply:
>
>    do xStr <- getLine
>       print (stringToInt xStr)
>
>
> Greets,
> Ertugrul
>
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://ertes.de/
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110808/3074a6b8/attachment.htm>


More information about the Beginners mailing list