Thanks for all the help. I think things are much clearer now. And this bit:

main = do putStrLn "Hello, what is your name?"
          name <- getLine
          putStrLn ("Hello, " ++ name ++ "!")

Looks quite straight forward.

I just wrote my very first IO program with Haskell:
--//--
main = do
        x <- getLine
        putStrLn( show(length x) )
--//--

That's not so scary. The next thing I need to figure out is how to act on the input data itself (not just its length). For example, if I wanted a program to output the nth element of the fibonacci sequence:
--//--
$ ./fib 12
144
--//--

My first inclination would be to write it as:
--//--
main = do
        x <- getLine
        putStrLn( show(fib x) )
--//--

Of course that won't work because x is an IO String and 'fib' wants an Int. To it looks like I need to do a conversion "IO a -> b" but from what Cale said, that's not possible because it would defeat the referential transparency of Haskell.

Hmm... there must be a way to solve this problem though...

In any event, thanks for the help. I'm learning :)

Cheers,
Daniel.
--
     /\/`) http://oooauthors.org
    /\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/    I am not over-weight, I am under-tall.
   /
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to