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.

So, yes, I need *basic* knowledge of types (strings vs numbers) and the functions that convert from one to the other. But that's it. I don't need to know that "do" and "<-" are syntactics sugar, or what a monad is (heck, I don't know those things).

I think that the following is suitable for chapter 1:
--//--
main = do
        putStrLn "What is your name? "
        name <- getLine
        putStrLn("Hello " ++ name)
--//--

You don't need to learn about monads, or classes or lists for this. Yes, not even lists ("Use ++ to catenate strings"). All you need to know is strings, and that "name <- getLine" gets a line from input and puts it in 'name'.

I think that this is suitable for chapter 2:
--//--
main = do
        putStrLn "Please type a word:"
        word <- getLine
        putStrLn("This word has " ++ (show( length word)) ++ " letters")
--//--

Here you learn about numbers, and converting numbers to strings (show).

And this is for chapter 3:
--//--
main = do
        putStrLn "Please type a number:"
        number <- getLine
        putStrLn (number ++ "! = " ++ (show (fac read(number)))
--//--

Here you learn about converting a string to number. At some point between chapters 1 and 3 you'd learn how to write 'fac' (I guess chapter 1).

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