[Haskell-beginners] having trouble with helloworld style program
Michael Snoyman
michael at snoyman.com
Mon Aug 8 13:43:14 CEST 2011
On Mon, Aug 8, 2011 at 2:39 PM, Sunil S Nandihalli
<sunil.nandihalli at gmail.com> wrote:
> Hello everybody,
> All I want to do in the following code is to read an integer from stdin
> and print it back to stdout. Can somebody help me fix my code snippet
> below..
> Thanks,
> Sunil
>
> module Main where
> import Prelude
> stringToInt::String->Int
> stringToInt str = read str
> main =
> do x<-getLine
> y<-stringToInt x
> print y
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
The code is *almost* right. You just need to change the second to last
line to be:
let y = stringToInt x
Hoping someone else steps in with a good, beginner-friendly
explanation of *why*.
Michael
More information about the Beginners
mailing list