
Hello all, I'm trying to write the simplest possible Haskell program, and I'm not getting anywhere. I have installed Hugs, GHC and GHCI. I want to run the following program: fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1) This is what I see: $ hugs Hugs.Base> fac :: Integer -> Integer ERROR - Undefined variable "fac" Hugs.Base> fac 0 = 1 ERROR - Syntax error in input (unexpected `=') $ ghci Prelude> fac :: Integer -> Integer <interactive>:1:0: Not in scope: `fac' Prelude> fac 0 = 1 <interactive>:1:6: parse error on input `=' $ # Write the program to fac.hs $ ghc fac.hs fac.hs:1:0: The main function `main' is not defined in module `Main' When checking the type of the main function `main' This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function. It's hard not to be put off by this. I love the theory behind Haskell, but the practice of it seems to be a real problem. I hope someone will show me how to make this program work. Even better, I hope someone will fix the compilers and interpreters if they need fixing, or fix the documentation if that's what needs fixing. Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On 12/18/05, Daniel Carrera
Hello all,
I'm trying to write the simplest possible Haskell program, and I'm not getting anywhere.
I have installed Hugs, GHC and GHCI. I want to run the following program:
fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
This is what I see:
$ hugs Hugs.Base> fac :: Integer -> Integer ERROR - Undefined variable "fac" Hugs.Base> fac 0 = 1 ERROR - Syntax error in input (unexpected `=')
$ ghci Prelude> fac :: Integer -> Integer
<interactive>:1:0: Not in scope: `fac' Prelude> fac 0 = 1 <interactive>:1:6: parse error on input `='
$ # Write the program to fac.hs $ ghc fac.hs
fac.hs:1:0: The main function `main' is not defined in module `Main' When checking the type of the main function `main'
GHC is a compiler. If you want to compile to a binary then you must define a function called 'main'. Otherwise just load the file in ghci (`ghci fac.hs`). -- Friendly, Lemmih

Lemmih wrote:
GHC is a compiler. If you want to compile to a binary then you must define a function called 'main'. Otherwise just load the file in ghci (`ghci fac.hs`).
I would expect GHC to be able to compile a program with a function that is not called 'main'. I wouldn't expect it to print anything when run, but I would expect it to compile. `ghci fac.hs` doesn't give any errors. I don't understand why loading the file like that is ok but typing the entries is not. This might be a problem for people exporing the language. Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On 12/18/05, Daniel Carrera
Lemmih wrote:
GHC is a compiler. If you want to compile to a binary then you must define a function called 'main'. Otherwise just load the file in ghci (`ghci fac.hs`).
I would expect GHC to be able to compile a program with a function that is not called 'main'. I wouldn't expect it to print anything when run, but I would expect it to compile.
It can. To compile a module use the "-c" ('c' for "compile"). If you want an executable you will need to have an entry-point (which is main). Typically you would write your program in a file, have a main function, and then write ghc --make MyMainModule.hs -o MyExecutableName Optionally adding "-O" or "-O2" for optimisation. The "--make" flag is really useful as it will cause GHC to track down dependencies automatically and compile them if needed (reducing the need for makefiles etc.). /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

Am Sonntag, 18. Dezember 2005 17:42 schrieb Daniel Carrera:
Lemmih wrote:
GHC is a compiler. If you want to compile to a binary then you must define a function called 'main'. Otherwise just load the file in ghci (`ghci fac.hs`).
I would expect GHC to be able to compile a program with a function that is not called 'main'. I wouldn't expect it to print anything when run, but I would expect it to compile.
So you want a program that doesn't contain a main variable to be compiled into an executable which does nothing? This doesn't seem to make much sense. In addition, Haskells requirement of a main variable is nothing new. Take C, C++, Java, PASCAL. They all require you to somehow specify a main program/function/method.
`ghci fac.hs` doesn't give any errors. I don't understand why loading the file like that is ok but typing the entries is not.
Because the interactive environments are about evaluating expressions based on declarations which were made in Haskell source files, not about creating new declarations. Expressions and declarations are just two different things. I think, Cale explained why it might be a bad idea to allow entering declarations at the command line.
This might be a problem for people exporing the language.
Hmm, don't know.
Best, Daniel.
Best wishes, Wolfgang

Wolfgang Jeltsch wrote:
In addition, Haskells requirement of a main variable is nothing new.
Certainly nothing new. I just wish that the documentation I read had told me about it.
`ghci fac.hs` doesn't give any errors. I don't understand why loading the file like that is ok but typing the entries is not.
Because the interactive environments are about evaluating expressions based on declarations which were made in Haskell source files, not about creating new declarations. Expressions and declarations are just two different things. I think, Cale explained why it might be a bad idea to allow entering declarations at the command line.
Ok. I think I understand. I'm sure this will make more sense later.
This might be a problem for people exporing the language.
Hmm, don't know.
I think that usability is important. I'm a big fan of usability. You don't want to give artificial barriers to people who are just starting to explore the language. Those are the people most likely to turn away. Make the first step as simple as possible. The mini-tutorial I posted to the list would be enough. It's little more than a paragraph, and it gets the user past that first step. Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Daniel Carrera wrote:
Hello all,
I'm trying to write the simplest possible Haskell program, and I'm not getting anywhere.
I have installed Hugs, GHC and GHCI. I want to run the following program:
fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
$ ghci Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) } Prelude> fac 12 479001600
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function. It's hard not to be put off by this. I love the theory behind Haskell, but the practice of it seems to be a real problem.
I hope someone will show me how to make this program work. Even better, I hope someone will fix the compilers and interpreters if they need fixing, or fix the documentation if that's what needs fixing.
Best, Daniel.
Almost everything is explained under http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html The main things is: The ghci prompt accepts either command, starting with a color such as :load "filename" or haskell IO code, since it is in a do-block. Thus let is required. The 2-D Layout syntax does not work at the ghci prompt, thus the braces-and-semicolon style I used. More typically you would write your code in a file, as shown in: http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html

Chris Kuklewicz wrote:
Almost everything is explained under
http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html
Ok. How would a visitor to the Haskell site find this document? If this is the correct document for a beginner to start with Haskell, perhaps the site should be updated to point to it instead of the documents it currently points to. I find some usability problems in the documentation section. Think of usability in terms of barriers. If you have low barriers, a lot of people will have enough motivation to cross them and get started with Haskell. If the barriers are very high, only the most intent and motivated users will get started. Barriers are bad. Consider some barriers for a user who wants to learn Haskell: * There's no way for a new user to figure out how to successfully run the simplest Haskell program. * The first tutorial listed requires the user to give up some personal information before getting the tutorial. These are very significant barriers. Sure, it's not all bad. For example, Haskell has a friendly community (low barrier). But the barriers that exist are a problem because they hit the person who is trying to take the very very first step. If you can make that *fist* step easier, more people will take it.
The main things is: The ghci prompt accepts either command, starting with a color such as :load "filename" or haskell IO code, since it is in a do-block. Thus let is required.
I understand that the design of Haskell might force this behaviour (I don't know, but I guess it must). The best solution I can think of (from a usability POV) is to provide a very brief tutorial, just 1/2 page, just enough to get someone through "hello world", and put it right at the top of the Learning Haskell section. I would remove the Intro section (it would fit better on the front page) and replace it with a 1/2 page tutorial. Something like this: -------------// Sugestion ------------- 40-SECOND INTRO TO HASKELL (You must have <link>Hugs or GHC installed</link>) 1. Open a text editor and type: fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1) 2. Save as "fac.hs" 3. On a terminal: $ ghci Prelude> :load fac.hs Compiling Main ( fac.hs, interpreted ) Ok, modules loaded: Main. *Main> fac 12 479001600 4. Press Ctrl+D to exit. For more information, look at the following tutorials: -------------// Sugestion ------------- There. That's brief, and it's enough to get the user past the first step. It sends the message that Haskell is not so scary.
More typically you would write your code in a file, as shown in: http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html
Thanks. Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On 18/12/05, Daniel Carrera
Chris Kuklewicz wrote:
Almost everything is explained under
http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html
Ok. How would a visitor to the Haskell site find this document? If this is the correct document for a beginner to start with Haskell, perhaps the site should be updated to point to it instead of the documents it currently points to.
I find some usability problems in the documentation section. Think of usability in terms of barriers. If you have low barriers, a lot of people will have enough motivation to cross them and get started with Haskell. If the barriers are very high, only the most intent and motivated users will get started. Barriers are bad.
Consider some barriers for a user who wants to learn Haskell:
* There's no way for a new user to figure out how to successfully run the simplest Haskell program. * The first tutorial listed requires the user to give up some personal information before getting the tutorial.
Google for "Yet Another Haskell Tutorial pdf", and you'll find that this form can be subverted if you actually care. It also accepts completely random values.
These are very significant barriers.
Sure, it's not all bad. For example, Haskell has a friendly community (low barrier). But the barriers that exist are a problem because they hit the person who is trying to take the very very first step. If you can make that *fist* step easier, more people will take it.
The main things is: The ghci prompt accepts either command, starting with a color such as :load "filename" or haskell IO code, since it is in a do-block. Thus let is required.
I understand that the design of Haskell might force this behaviour (I don't know, but I guess it must). The best solution I can think of (from a usability POV) is to provide a very brief tutorial, just 1/2 page, just enough to get someone through "hello world", and put it right at the top of the Learning Haskell section. I would remove the Intro section (it would fit better on the front page) and replace it with a 1/2 page tutorial. Something like this:
-------------// Sugestion ------------- 40-SECOND INTRO TO HASKELL
(You must have <link>Hugs or GHC installed</link>)
1. Open a text editor and type: fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
2. Save as "fac.hs" 3. On a terminal:
$ ghci Prelude> :load fac.hs Compiling Main ( fac.hs, interpreted ) Ok, modules loaded: Main. *Main> fac 12 479001600
4. Press Ctrl+D to exit.
For more information, look at the following tutorials: -------------// Sugestion -------------
There. That's brief, and it's enough to get the user past the first step. It sends the message that Haskell is not so scary.
More typically you would write your code in a file, as shown in: http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html
Thanks.
Best, 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

Am Sonntag, 18. Dezember 2005 18:02 schrieb Daniel Carrera:
Chris Kuklewicz wrote:
Almost everything is explained under
http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html
Ok. How would a visitor to the Haskell site find this document?
The point is that the visitor should know that he/she might need a document about GHCi if he/she wants to use GHCi. A introductionary document about Haskell might not explain a specific Haskell system. If you read a book which is about C++ in general, it won't tell you how to use the GNU C++ compiler or Microsoft Visual C++. If you know that you need some GHC(i) documentation, it shouldn't be much of a problem to find it. Go to the GHC homepage, click on "Documentation" and you will find "The User's Guide" whose short description tells you that it covers GHCi.
If this is the correct document for a beginner to start with Haskell, perhaps the site should be updated to point to it instead of the documents it currently points to.
At least, the site currently points to the GHC homepage.
I find some usability problems in the documentation section.
Which documentation section do you mean?
Think of usability in terms of barriers. If you have low barriers, a lot of people will have enough motivation to cross them and get started with Haskell. If the barriers are very high, only the most intent and motivated users will get started. Barriers are bad.
Maybe, some barriers could be lowered but I don't think that the barriers are currently "very high". What do others think?
Consider some barriers for a user who wants to learn Haskell:
* There's no way for a new user to figure out how to successfully run the simplest Haskell program.
There is! "The Hugs 98 User's Guide" and "The GHC User's Guide".
* The first tutorial listed requires the user to give up some personal information before getting the tutorial.
That's bad, of course.
These are very significant barriers.
Concerning the latter one, I agree with you.
Sure, it's not all bad. For example, Haskell has a friendly community (low barrier).
:-)
But the barriers that exist are a problem because they hit the person who is trying to take the very very first step. If you can make that *fist* step easier, more people will take it.
What do you mean with "*fist* step"? :-) :-)
[...]
Best, Daniel.
Best wishes, Wolfgang

Wolfgang Jeltsch wrote:
The point is that the visitor should know that he/she might need a document about GHCi if he/she wants to use GHCi. A introductionary document about Haskell might not explain a specific Haskell system. If you read a book which is about C++ in general, it won't tell you how to use the GNU C++ compiler or Microsoft Visual C++.
I just Googled for "Introduction to C". The first link was: http://www.le.ac.uk/cc/tutorials/c/ It includes a brief section on both MS Visual C++ and the Unix CC. Maybe I've just been lucky in reading all the right tutorials until now :) but every time I learn a new language, the intro tutorial tells me how to get Hello World running. I have never looked for a compiler tutorial. I guess that Haskell is unique among interpreted languages in that there are two compilers and they work different. I wouldn't expect a huge and elaborate description of Hugs or GHCI on a tutorial. I'd expect a brief "If you have Hugs do xyz and if you have GHC do abc".
If you know that you need some GHC(i) documentation, it shouldn't be much of a problem to find it.
But you see, I didn't. I thought I needed "Haskell" documentation, so that's what I looked for.
At least, the site currently points to the GHC homepage.
Yes. I thought it was for the purpose of installing it. Since I installed it with 'apt-get install ghc' I didn't think to click there.
I find some usability problems in the documentation section.
Which documentation section do you mean?
The web page titled "Learning Haskell".
Maybe, some barriers could be lowered but I don't think that the barriers are currently "very high". What do others think?
To be fair, the barriers are not as high as they could be. For example, the Haskell community is friendly and helpful and that's a low barrier. It took no time between my posting a question and getting a good answer. So in the end it took me no more than a day to write Hello World. I do suggest that the "Learning Haskell" page could be improved with a brief (couple of paragraph) tutorial to get someone through Hello world. Or perhaps update the tutorials to say that. I wrote a suggestion on another post.
* There's no way for a new user to figure out how to successfully run the simplest Haskell program.
There is! "The Hugs 98 User's Guide" and "The GHC User's Guide".
Okay, I stand corrected. I rephrase the concern as "The links that say Learn Haskell don't show you how to run a simple Haskell program".
* The first tutorial listed requires the user to give up some personal information before getting the tutorial.
That's bad, of course.
These are very significant barriers.
Concerning the latter one, I agree with you.
:)
But the barriers that exist are a problem because they hit the person who is trying to take the very very first step. If you can make that *fist* step easier, more people will take it.
What do you mean with "*fist* step"? :-) :-)
Heh... typing accuracy is over-rated. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Am Montag, 19. Dezember 2005 12:13 schrieb Daniel Carrera:
[...]
I guess that Haskell is unique among interpreted languages
Haskell is not an "interpreted language". There are Haskell interpreters, there are Haskell compilers.
in that there are two compilers and they work different.
The basic principles of the interactive environments (Hugs and GHCi) are the same, and so are the basic principles of the compilers (GHC, nhc98, ...). Of course, they differ in the details. But so do different C compilers.
[...]
What do you mean with "*fist* step"? :-) :-)
Heh... typing accuracy is over-rated.
Well, I couldn't resist... ;-)
Cheers, Daniel.
Best wishes, Wolfgang

On Monday 19 December 2005 12:13, Daniel Carrera wrote:
Wolfgang Jeltsch wrote:
* There's no way for a new user to figure out how to successfully run the simplest Haskell program.
There is! "The Hugs 98 User's Guide" and "The GHC User's Guide".
Okay, I stand corrected. I rephrase the concern as "The links that say Learn Haskell don't show you how to run a simple Haskell program".
Hello, very interesting exchange, this. It appears you are experiencing some (mild) culture shock here. It is typical for people in the Haskell community to view things in a rather principled way. A language tutorial is supposed to introduce /the language/. If you want to know how to compile or execute a Haskell program, well then, look at the appropriate tutorial on the /implementation/. At first this may appear like deliberately creating hurdles, but it isn't, it's merely the way many (though not all) Haskell people tend to think. They take it for granted that a new user is at least educated enough to be aware of the difference between the language itself, and its concrete implementation in the form of an interpretation or a compilation system. , Now although it appears you very well know the difference, you just aren't used to it being shoved in your face ;-) Well, another quirk is that adherence to what is custom (e.g. in other language communities) is not viewed as an important value among "lambda folks", at least not if there is some general guiding principle that stands against it (in this case: the language itself is not to be confused with its concrete implementation). Once SPJ famously called it "wairing the hair shirt", refering to the unusual way in which Haskell evolved in an extremely principled way (purely functional, lazy) which, for instance, during the first years made programming IO quite a challenge... until monadic IO was invented, so we(*) could finally do it *right*. Although I like this attitude very much in principle (pun intended), I can see that for newcomers this /can/ be a hurdle and I would recommend to tone it down a bit and compromise where it doesn't really do any harm -- such as explaining how to load and execute a Haskell program (using Hugs for instance) in a beginner's tutorial on (yes) Haskell The Language Itself ;-) Cheers, Ben (*) Figuratively speaking. Personally, I didn't know anything about Haskell back then.

Chris Kuklewicz
Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) }
As somebody made me aware just the other day, the bracer are only necessary for nested expressions. So you can just use ; for line breaks: Prelude> let fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) -k -- If I haven't seen further, it is by standing in the footprints of giants

Try ghci fac.hs. You will then have an interactive session with access to the definitions in your file. Then after you've played with you creation a bit, check out http://haskell.org/learning.html Welcome and enjoy! Joel

Joel Koerwer wrote:
Then after you've played with you creation a bit, check out http://haskell.org/learning.html http://haskell.org/learning.html
Thank you. I did find that page, and it was very easy to find. The problem is that the content of that page, and its links, didn't show me how to write a Haskell program (like you did). Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Am Sonntag, 18. Dezember 2005 18:04 schrieb Daniel Carrera:
Joel Koerwer wrote:
Then after you've played with you creation a bit, check out http://haskell.org/learning.html http://haskell.org/learning.html
Thank you. I did find that page, and it was very easy to find.
There's a link on the Haskell Homepage to this page.
The problem is that the content of that page, and its links, didn't show me how to write a Haskell program (like you did).
If you want to know how to feed, for example, Hugs with your Haskell program, you might have to have a look at some Hugs documentation. Remember that different Haskell implementations like Hugs, GHCi etc. may have different ways of reading Haskell programs. So it's advisable to have a look at some documentation which is specifically about the Haskell system you use. On the "Learning Haskell" page you can click, for example, on the "Hugs" link, then on "Documentation" and then on "The Hugs 98 User's Guide" or "The Hugs 98 User Manual".
Best, Daniel.
Best wishes, Wolfgang

Wolfgang Jeltsch wrote:
The problem is that the content of that page, and its links, didn't show me how to write a Haskell program (like you did).
If you want to know how to feed, for example, Hugs with your Haskell program, you might have to have a look at some Hugs documentation. Remember that different Haskell implementations like Hugs, GHCi etc. may have different ways of reading Haskell programs.
"remember"? This is the first time I hear this, and I'm bewildered. I expect two C compilers to be able to compile a correct C program. Certainly a "hello world" program. How is it possible that two Haskell implementations disagree on how to read a Haskell program? (unless it's an advanced program with very unique compiler features - which is bad).
On the "Learning Haskell" page you can click, for example, on the "Hugs" link, then on "Documentation" and then on "The Hugs 98 User's Guide" or "The Hugs 98 User Manual".
I doubt a lot of people who didn't already know about Haskell would think to click on the manual for the *compiler* instead of the link that says "Haskell Tutorial". Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On Mon, Dec 19, 2005 at 10:14:07AM +0000, Daniel Carrera wrote:
Wolfgang Jeltsch wrote:
If you want to know how to feed, for example, Hugs with your Haskell program, you might have to have a look at some Hugs documentation. Remember that different Haskell implementations like Hugs, GHCi etc. may have different ways of reading Haskell programs.
"remember"? This is the first time I hear this, and I'm bewildered. I expect two C compilers to be able to compile a correct C program. Certainly a "hello world" program. How is it possible that two Haskell implementations disagree on how to read a Haskell program? (unless it's an advanced program with very unique compiler features - which is bad).
I think what Wolfgang meant was that different Haskell implementations may have: - different executable names, so you have to invoke them differently - different options - different style of work etc... Of course, all of them should accept all Haskell 98 programs. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

Tomasz Zielonka wrote:
I think what Wolfgang meant was that different Haskell implementations may have: - different executable names, so you have to invoke them differently - different options - different style of work etc...
Of course, all of them should accept all Haskell 98 programs.
Ah. Thanks. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

Daniel Carrera wrote:
Hello all,
I'm trying to write the simplest possible Haskell program, and I'm not getting anywhere.
I have installed Hugs, GHC and GHCI. I want to run the following program:
fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
$ ghci Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n * fac (n-1) } Prelude> fac 12 479001600
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function. It's hard not to be put off by this. I love the theory behind Haskell, but the practice of it seems to be a real problem.
I hope someone will show me how to make this program work. Even better, I hope someone will fix the compilers and interpreters if they need fixing, or fix the documentation if that's what needs fixing.
Best, Daniel.
Almost everything is explained under http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html The main things is: The ghci prompt accepts either command, starting with a color such as :load "filename" or haskell IO code, since it is in a do-block. Thus let is required. The 2-D Layout syntax does not work at the ghci prompt, thus the braces-and-semicolon style I used. More typically you would write your code in a file, as shown in: http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html

The ordinary usage pattern, which I recall is actually described in a
number of the tutorials, and on the wiki, probably in a number of
places, is to write your program text into a file with an editor, and
then load it at a terminal with either ghci fac.hs or hugs fac.hs.
(See http://www.haskell.org/hawiki/HaskellNewbie/HaskellInterpreterUsage,
as that's a conglomeration of a few of the question/answers that were
scattered about)
At that point, you can evaluate *expressions* at the ghci/hugs prompt,
to observe the operation of your program (think of it like a
debugger). This is different from entering declarations in that you
can't define things. GHCi specifically allows function/value
declarations with let (as it is somewhat emulating the inside of a
do-block), but it won't allow other kinds (data declarations, etc.).
"let x = 5 in x * x" works in either one, as it is an expression.
Note that you can type :r at the ghci or hugs prompt to reload your
file whenever you save it in your editor, so it's fairly easy to keep
things in sync.
If you want to compile your program with ghc proper, you'll need a
main action. Otherwise, well, what would the produced binary do? A
simple main is provided by printing some value, so I could add to your
program
main = print (fac 1000)
and then compile it, and the binary produced would print the integer
value of 1000! to the terminal.
Note that the interactive environments would have a hard time loading
ad-hoc Haskell code on stdin, as there may be, for instance, mutually
recursive bindings, and data types used in one function might be
declared later in the file. (Thus, testing that function would result
in an error message which currently isn't possible, a run-time type
error.) Further, the layout rule complicates the issue as to whether a
given line was intended as an expression, or the first part of a
declaration. I think it would be more confusing than what we currently
have.
Hope this helps,
- Cale
On 18/12/05, Daniel Carrera
Hello all,
I'm trying to write the simplest possible Haskell program, and I'm not getting anywhere.
I have installed Hugs, GHC and GHCI. I want to run the following program:
fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
This is what I see:
$ hugs Hugs.Base> fac :: Integer -> Integer ERROR - Undefined variable "fac" Hugs.Base> fac 0 = 1 ERROR - Syntax error in input (unexpected `=')
$ ghci Prelude> fac :: Integer -> Integer
<interactive>:1:0: Not in scope: `fac' Prelude> fac 0 = 1 <interactive>:1:6: parse error on input `='
$ # Write the program to fac.hs $ ghc fac.hs
fac.hs:1:0: The main function `main' is not defined in module `Main' When checking the type of the main function `main'
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function. It's hard not to be put off by this. I love the theory behind Haskell, but the practice of it seems to be a real problem.
I hope someone will show me how to make this program work. Even better, I hope someone will fix the compilers and interpreters if they need fixing, or fix the documentation if that's what needs fixing.
Best, 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

Am Sonntag, 18. Dezember 2005 17:25 schrieb Daniel Carrera:
[...]
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function.
Hello Daniel, honestly, I have to say that during my years with Haskell, this seems to be the first time that I see somebody trying to enter a Haskell program via the command line of an interactive environment. So I suppose that it's not "a lot of people" who experience the problems you do.
It's hard not to be put off by this. I love the theory behind Haskell, but the practice of it seems to be a real problem.
Did you have a look at the Hugs or GHCi documentation? I'm very sure, it will tell you that what you may enter at the command line are (merely) expressions to evaluate and special commands like :t for displaying the type of an expression, and that the Haskell declarations (normally) have to be read from a file.
I hope someone will show me how to make this program work. Even better, I hope someone will fix the compilers and interpreters if they need fixing, or fix the documentation if that's what needs fixing.
I suppose that neither the compilers and interpreters nor the documentation need(s) fixing, although I might be wrong with the documentation.
Best, Daniel.
Best wishes, Wolfgang

Wolfgang Jeltsch wrote:
honestly, I have to say that during my years with Haskell, this seems to be the first time that I see somebody trying to enter a Haskell program via the command line of an interactive environment.
Well, I tried all three (Hugs, GHCI, GHC). The problem is that the tutorials I found didn't tell me how to run a Haskell program once it was written.
Did you have a look at the Hugs or GHCi documentation?
I took a look at all the tutorials listed in the "Learn Haskell" page (the first one asked me for private information!). If those are not the tutorials that a new user should be reading, then the problem is on the web page. It should point to the correct tutorials. This is a usability problem.
I suppose that neither the compilers and interpreters nor the documentation need(s) fixing, although I might be wrong with the documentation.
I'm sure the compilers and interpreters are doing their job. It's the documentation/usability side. You have to tell users how to run a program before you show them anything else. Any of the following would be an apt solution: 1) Update the tutorials linked to tell the user how to run a program. 2) Update the web page to link to the correct tutorial (if that's the problem). 3) Update the web page to include a brief (1/2) page tutorial explaining this first step. You see, as a site visitor, I have to assume that the tutorials you are giving me are the ones you expect I should read. It is nearly impossible for a new user to know to read the GHCI tutorial. Not only is it not listed, but since when do you read the GCC tutorial when you want to get started with C? You'd expect the GCC tutorial to be relevant when you want more advanced compile-time options. The GCC tutorial assumes that you know how to write a C program. It doesn't tell you to put a main() function. That information is in the "Introduction to C" tutorial. Best, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

OOn Mon, 19 Dec 2005 10:50:00 +0100, Wolfgang Jeltsch
Am Sonntag, 18. Dezember 2005 17:25 schrieb Daniel Carrera:
[...]
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function.
honestly, I have to say that during my years with Haskell, this seems to be the first time that I see somebody trying to enter a Haskell program via the command line of an interactive environment. So I suppose that it's not "a lot of people" who experience the problems you do.
I sympathise with Daniel's problems. I have hit many of them, as well. As Daniel said, they are not complete road blocks, merely "bumps" in the learning curve. Part of the problem may be that much of Haskell's tutorial material is focused on introducing functional programming (which is a new concept to the target audience), coupled with the fact that IO and imperative programming is a relatively "advanced" concept. That means that writing standalone programs (as well as being somewhat compiler-dependent in its details) takes a while to be discussed. Example: main is first mentioned in "A Gentle Introduction to Haskell" in chapter 7.1. That's a *lot* of reading before you get to write "Hello, world"...
I suppose that neither the compilers and interpreters nor the documentation need(s) fixing, although I might be wrong with the documentation.
I suspect that the reference documentation is fine, and the tutorials are great, given what they are trying to do. But there is scope for a very prominent "Getting going" document. Daniel's "40-second intro to Haskell" looks good. Expand it a little with a few lines showing tow to build and compile a "Hello, world" program in GHC and Hugs (with a disclaimer that the code itself is magic for now, you'll understand when you read about monads and the IO monad) to help people who need to get over the "but how do I write a *program*" hump, and you're pretty much there. Paul.

Wolfgang Jeltsch wrote:
Am Sonntag, 18. Dezember 2005 17:25 schrieb Daniel Carrera:
[...]
This is a real problem for Haskell. I expect that a lot of people try Haskell and give up because they can't even write the simplest function.
Hello Daniel,
honestly, I have to say that during my years with Haskell, this seems to be the first time that I see somebody trying to enter a Haskell program via the command line of an interactive environment. So I suppose that it's not "a lot of people" who experience the problems you do. .... I suppose that neither the compilers and interpreters nor the documentation need(s) fixing, although I might be wrong with the documentation.
Best, Daniel.
Best wishes, Wolfgang
FWIW: This is my second or third day with Haskell. I was totally stumped until I searched out "Yet Another Haskell Tutorial". I tried starting with "A Gentle Introduction...", but it never told me how to get started. It talked at great length about the language, and I'm certain that it will be very useful in a week or so, but it sure isn't the way to get started. So he's not unique. I couldn't figure out why Hugs wouldn't interpret what I was certain were legitimate Haskell statements. (I'm still not sure why. Gentle introduction is a bit of a rough start. I'm confused between type declarations and variable assignments, etc. I'm sure this will work out over time, but right now the confusion is pretty severe.) And in "A Gentle Introduction..." I've yet to encounter a module statement. Perhaps I missed it, perhaps it's new, perhaps it's only used in batch compilation? Well, I'll find out eventually. "Yet Another ..." mentioned it right off, and I got Hello World working within 5 minutes (with my own customizations, to also append the value of x onto the message). A language manual is not a tutorial. It's important, but first you need a place to start.

FWIW: This is my second or third day with Haskell. I was totally stumped until I searched out "Yet Another Haskell Tutorial". I tried starting with "A Gentle Introduction...", but it never told me how to get started. It talked at great length about the language, and I'm certain that it will be very useful in a week or so, but it sure isn't the way to get started.
So he's not unique. I couldn't figure out why Hugs wouldn't interpret what I was certain were legitimate Haskell statements. (I'm still not sure why. Gentle introduction is a bit of a rough start. I'm confused between type declarations and variable assignments, etc. I'm sure this will work out over time, but right now the confusion is pretty severe.) And in "A Gentle Introduction..." I've yet to encounter a module statement. Perhaps I missed it, perhaps it's new, perhaps it's only used in batch compilation? Well, I'll find out eventually. "Yet Another ..." mentioned it right off, and I got Hello World working within 5 minutes (with my own customizations, to also append the value of x onto the message).
A language manual is not a tutorial. It's important, but first you need a place to start.
Yeah, the "Gentle Introduction" could reallly only be considered gentle if you're already familiar with other functional languages such as ML, or perhaps in comparison to reading the report. Yet Another Haskell Tutorial is usually where I point newcomers. The reason that GHCi and Hugs don't accept things like function and type declarations is that they are intended only to evaluate expressions (that is, things which evaluate to values), as opposed to reading declarations. You're expected to put all your declarations in a file, where all the various dependencies can be resolved, and then load that with your favourite interactive environment for testing, but not really so much for development. I like to keep an editor open with my module alongside a running GHCi session. When I'm ready to try out a new declaration, I'll save the file, and type ":r" in GHCi, which reloads my file. In GHCi (as opposed to hugs) it's possible to make function and value declarations at the prompt with let: Prelude> let fac n = product [1..n] Prelude> fac 12 479001600 However, these are not very permanent -- they go away when you reload your file, and future declarations shadow previous ones. There's also no way to save all the declarations you've made like this, and as mentioned, it only works for functions and values. So really, it's a lot nicer to save all your declarations in a file as you work. As to the confusion between type and value declarations (it's a little odd to call them "assignments" by the way, because they're really more declarations -- you can't reassign them later), it should sort itself out on its own in a short while, but the basic difference is that value declarations define the value to which some name or pattern evaluates, whereas type declarations say what type of thing it should work out to. If you write: x :: String x = [1,2,3] you'll get an error, because [1,2,3] isn't a String. Haskell can largely work out appropriate types for things on its own, so if you're ever sure you have the definition right, but not sure exactly what type it should have, you can ask GHCi or Hugs to tell you using :t expr where expr is the expression you'd like the type for. Haskell's type system is a good way to eliminate wide classes of potential bugs. In my experience, I'd estimate that 95% or so of the bugs which I'd experience at runtime in most 'popular' languages with lesser type systems (C, Java, Lisp, Ruby etc.) become compile time errors. The vast majority of what remains are actual design flaws. When things compile, they usually work, to a much greater extent than I'd come to expect in most other languages. That said, the type system works a lot better when you include type declarations, because it provides lots of sanity checks -- it will still make sure that the types it infers for the functions and values are compatible with the types you're giving them explicitly. Also, error messages from the compiler can get a lot tighter and can point you at the problems in your code more swiftly. So even though it's largely optional, it's good to include types for things whenever it's not too inconvenient. hope this helps, - Cale

FWIW: This is my second or third day with Haskell. I was totally stumped until I searched out "Yet Another Haskell Tutorial". I tried starting with "A Gentle Introduction...", but it never told me how to get started. It talked at great length about the language, and I'm certain that it will be very useful in a week or so, but it sure isn't the way to get started.
The Gentle Introduction is not at all gentle (it is excellent at what it does, but it assumes a level of sophistication that is well above what a large portion of beginning Haskell programmers have achieved when they begin learning the language). There are several other tutorial's on the net that are far better at introducing the neophyte to the language (as you've already discovered), but my experience in the classroom is that Simon Thompson's book (The Craft of Functional Programming) is probably just about right as an introduction (and subsequently as a reference as well), especially for self study. Now, please do not misunderstand: Simply because I suggest Thompson's book does not mean I am trying to sell it--but over the past 4 years or so, I have not yet found anything else that got my students writing the language as quickly, and please be assured that they have demonstrated quite some skill at ferreting out introductory material on the web (I need to be quite careful with the exercies I assign to make sure that the answers can't be copied . . . :)> ). Last, you should note that Thompson, like just about everything else on the subject, is far from complete--there is all sorts of other "stuff" that you will pick up from the available Haskell system documentation, but that can wait until you have simple programs running. Best, Murray Gross CIS Dept., Brooklyn College
participants (14)
-
Benjamin Franksen
-
Cale Gibbard
-
Charles Hixson
-
Chris Kuklewicz
-
Chris Kuklewicz
-
Daniel Carrera
-
Joel Koerwer
-
Ketil Malde
-
Lemmih
-
Murray Gross
-
Paul Moore
-
Sebastian Sylvan
-
Tomasz Zielonka
-
Wolfgang Jeltsch