[Haskell-cafe] Re: Tutorial uploaded

Daniel Carrera daniel.carrera at zmsl.com
Thu Dec 22 07:13:06 EST 2005

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:
> 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).

      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    \/_/    I am not over-weight, I am under-tall.

More information about the Haskell-Cafe mailing list