[Haskell-cafe] Re: First steps in Haskell

Daniel Carrera daniel.carrera at zmsl.com
Tue Dec 20 12:07:50 EST 2005


Donn Cave wrote:
> I understand that interactive mode can be useful, I'm just wondering
> whether it belongs with Hello world in the scheme of things, or if
> at that first step it would be better to focus on the language.

Let's compare sample instructions:

Interactive mode:
-----------------
1. Write this on a file and save it as prog.hs
    ----
    fac 0 = 1
    fac n | n > 0 = n * fac(n-1)
    ----
2. Type ghci on a terminal.
3. Load the program with ":load prog.hs"
4. Type "fac 12"

Compiled mode:
---------------
1. Write this on a file and save it as "prog.hs"
    ----
    main = print fac 12

    fac 0 = 1
    fac n | n > 0 = n * fac(n-1)
    ----
2. Type "ghc prog.hs -o prog" on a terminal.
3. Run the program with "./prog"


Comparison:
~~~~~~~~~~~
1. The "compiled mode" instructions are only 1 step smaller, and that's 
because that step was moved into the program itself. You still need to 
explain that bit.
2. The "compiled mode" instructions also introduce "main" and "print".


Over-all, I think that the compiled mode instructions are *marginally* 
more complicated. Not enough to choose one over the other. I would 
choose the interactive mode because it is friendlier to experimentation.

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


More information about the Haskell-Cafe mailing list