[Haskell-cafe] Re: Tutorial uploaded

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Dec 22 07:51:45 EST 2005

On 12/22/05, Daniel Carrera <daniel.carrera at zmsl.com> wrote:
> S Koray Can wrote:
> >> As a newbie... I agree that a newbie should be able to write this
> >> fairly early on:
> >>
> >> main = do
> >>        x <- getLine()
> >>        putStrLn ("The answer is " ++ show(fib(read(x))))
> >>
> >
> > I'd agree for some definition of 'early'. I'll elaborate:
> [snip]
> >
> > The above code snippet contains typeclasses (show, read, monadic IO,
> > lists), syntactic sugar (do, <-). When you say a 'newbie' should be able
> > to write that early on, I'd interpret that as 'a newbie should be able
> > to regurgitate this early on'
> Well, I'm a newbie, and I wrote it. I have "enough" understanding to
> generate that code, even if I don't understand it all. This is what I know:
> * x is a string, fib wants an int, and "read" turns a string into a number.
> * "The answer is " is a string so you need ++. ++ expects a string, and
> "show" turns a number into a string.

Actually, it's a bit more than that (but still not harder than a
newbie would be able to grasp in the first chapter).
'read' convertes a string into *any* readable value. So 'read
"(4,1.23,'c')"' would convert a string into type
Likewise 'show' converts any showable value to a string. This include
numbers, but also includes a host of other values.


Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list