Writing functions in Haskell.

Hello, I'm trying to get started with Haskell. I must say that as good as the language must be, the documentation was been a source of frustration. Only one document actually showed me how to get started (ie. run hugs or ghci), and I was asked to give out my email address before getting it. Sigh... Well, in any event, I did get that document in the end and I've been reading through it. I've compiled Hugs on my Solaris workstation. There were no errors at compilation. Yet, I think there's something seriously wrong with my installation. I can't seem to be able to defin functions: my/prompt $ hugs .... Hugs.Base> fibs 1 = 1 ERROR - Syntax error in input (unexpected `=') And some functions seem to be missing. Hugs.Base> Char.toUpper 'a' ERROR - Undefined qualified variable "Char.toUpper" I was hoping that someone could confirm or deny that my Hugs installation is broken. Thank you for your time. Cheers, Daniel.

Hi,
I'm sorry to hear that you've been having a hard time finding good
references. From the example you gave, it looks like you're using "Yet
Another Haskell Tutorial" from http://www.isi.edu/~hdaume/htut/ which
is actually my favourite tutorial.
When using hugs or ghci, you should note that what these do is to
evaluate Haskell expressions and print (or execute) the results. To
actually write programs, (define data types and functions and such)
you'll need to fire up a text editor and enter your definitions into a
.hs file, which you can then load with your interpreter by passing the
filename on the commandline, or by using ":load filename.hs" at the
hugs or ghci prompt. I think this handles your first problem.
The second problem arises from hugs not doing the same thing as ghci
with respect to looking up qualified variable names (that is, those
with the module name specified, in this case, the standard module
Char). You can tell hugs to also load the Char module on top of
whatever code you have loaded by using the command ":also Char", after
which the prompt should look like
Char>
and you can try
toUpper 'a'
(without the Char, hugs doesn't seem to like qualified names, perhaps
someone else can explain this)
There are a number of resources which you might be interested in for
learning Haskell. You've already found the mailing lists, there is
also an IRC channel: #haskell on irc.freenode.net, where there are
plenty of people to help at any time. There's also a wiki at:
http://www.haskell.org/hawiki/FrontPage
The page http://www.haskell.org/hawiki/HaskellNewbie in particular
might be useful, as it answers lots of common questions from new
users. If you have additional questions, feel free to ask them there
and someone will probably respond fairly quickly.
I'm not sure how you found the tutorial, but if it wasn't from the
Learning Haskell page on haskell.org, I'll point you at that, since it
links to a bunch of other potentially useful resources:
http://www.haskell.org/learning.html
hope this helps,
- Cale
On 4/28/05, Daniel Carrera
Hello,
I'm trying to get started with Haskell. I must say that as good as the language must be, the documentation was been a source of frustration. Only one document actually showed me how to get started (ie. run hugs or ghci), and I was asked to give out my email address before getting it.
Sigh...
Well, in any event, I did get that document in the end and I've been reading through it. I've compiled Hugs on my Solaris workstation. There were no errors at compilation. Yet, I think there's something seriously wrong with my installation. I can't seem to be able to defin functions:
my/prompt $ hugs .... Hugs.Base> fibs 1 = 1 ERROR - Syntax error in input (unexpected `=')
And some functions seem to be missing.
Hugs.Base> Char.toUpper 'a' ERROR - Undefined qualified variable "Char.toUpper"
I was hoping that someone could confirm or deny that my Hugs installation is broken.
Thank you for your time.
Cheers, Daniel. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello Cale, Thank you for your help. Cale Gibbard wrote:
From the example you gave, it looks like you're using "Yet Another Haskell Tutorial" from http://www.isi.edu/~hdaume/htut/ which is actually my favourite tutorial.
The tutorial itself is quite good, and I like it. I guess I've had a long day, and when I was asked for my name and email I didn't react well. Oh well, life goes on.
When using hugs or ghci, you should note that what these do is to evaluate Haskell expressions and print (or execute) the results. To actually write programs, (define data types and functions and such) you'll need to fire up a text editor and enter your definitions into a .hs file, which you can then load with your interpreter by passing the filename on the commandline, or by using ":load filename.hs" at the hugs or ghci prompt. I think this handles your first problem.
Alright, got it. In hinsight, I misunderstood the tutorial. It showed me the function but it didn't actually say to type it in. Thanks for the help, I can write functions now. :-)
The second problem arises from hugs not doing the same thing as ghci [snip] You can tell hugs to also load the Char module on top of whatever code you have loaded by using the command ":also Char", after which the prompt should look like Char> and you can try toUpper 'a'
Alright, yes that works. Thanks!
There are a number of resources which you might be interested in for learning Haskell. You've already found the mailing lists, there is also an IRC channel: #haskell on irc.freenode.net, where there are plenty of people to help at any time.
Oh, good. IRC is good.
There's also a wiki at: http://www.haskell.org/hawiki/FrontPage The page http://www.haskell.org/hawiki/HaskellNewbie in particular might be useful, as it answers lots of common questions from new users. If you have additional questions, feel free to ask them there and someone will probably respond fairly quickly.
Ok, thanks. I really appreciate the help. And thank you for the friendly response. I'm eager to keep learning Haskell. The language looks very impressive. Cheers, Daniel.

On Thu, Apr 28, 2005 at 09:22:15PM -0400, Cale Gibbard wrote:
The second problem arises from hugs not doing the same thing as ghci with respect to looking up qualified variable names (that is, those with the module name specified, in this case, the standard module Char). You can tell hugs to also load the Char module on top of whatever code you have loaded by using the command ":also Char", after which the prompt should look like Char> and you can try toUpper 'a'
Might as well use :load -- in both case Char becomes the new current module, making the old current module inaccessible. Hal: Char.toUpper and Char.isLower in Chapter 3 seem to be a perennial stumbling block for Hugs users -- could you suggest that Hugs users load Char and just say toUpper and isLower instead?
(without the Char, hugs doesn't seem to like qualified names, perhaps someone else can explain this)
Since you ask: the names in scope at the Hugs prompt are exactly those in scope inside the current module, which is Char in this case. Now Char just imports and re-exports names from Data.Char, so inside Char there is no Char.toUpper, just toUpper and Data.Char.toUpper. On the other hand, inside a module Test that imports Char, you can refer to Char.toUpper as well as toUpper.

Hal: Char.toUpper and Char.isLower in Chapter 3 seem to be a perennial stumbling block for Hugs users -- could you suggest that Hugs users load Char and just say toUpper and isLower instead?
I just added a note about this :). Though the tutorial is mirrored in so many places by now, I'm sure the questions will still arise. -- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume

Am Freitag, 29. April 2005 18:01 schrieb Ross Paterson:
On Thu, Apr 28, 2005 at 09:22:15PM -0400, Cale Gibbard wrote:
The second problem arises from hugs not doing the same thing as ghci with respect to looking up qualified variable names (that is, those with the module name specified, in this case, the standard module Char). You can tell hugs to also load the Char module on top of whatever code you have loaded by using the command ":also Char", after which the prompt should look like Char> and you can try toUpper 'a'
Might as well use :load -- in both case Char becomes the new current module, making the old current module inaccessible.
There is a difference, though. Compare Test> :l Char Char> :n my_map ERROR - No names selected and Test> :a Char Char> :n my_map Test.my_map (1 names listed) So with :a(lso) the old module remains in sight for :n(ames) - and for :i in qualified form. Unfortunately I haven't found a way to use them, Hugs (Nov. 2003) in general refuses qualified names, though with some rather weird behaviour: Prelude> :l Test Test> :a Char Char> Prelude.map toUpper "buh" "BUH" Char> Data.Char.toUpper 'u' 'U' Char> :i Test.my_map my_map :: (a -> b) -> [a] -> [b] Char> Data.Char.toUpper 'u' ERROR - Undefined qualified variable "Data.Char.toUpper" Char> Prelude.map toUpper "buh" ERROR - Undefined qualified variable "Prelude.map" How can it be that Hugs knows these qualified names before I ask about Test.my_map but not afterwards? Puzzled, Daniel

Alright, I have what I believe must be a simple question. As one of the exercises for the Haskell tutorial I got I have to implement an alternative to the 'map' function. This is what I have: ----------------------------- my/prompt $ cat Test.hs module Test where my_map p [] = [] my_map p (x:xs) = p x : my_map p xs my/prompt $ hugs [snip] Hugs.Base> :l Test Test> :also Char Char> map toUpper "Hello" "HELLO" Char> my_map toUpper "Hello" ERROR - Undefined variable "my_map" ----------------------------- I can define other functions now (e.g. Fibonacci, length of a list). So I'm not sure why I'm doing wrong here. Even if my syntax is wrong in some way, the function should be defined. I would be grateful if anyone could point out my error. Cheers, Daniel.

Try: module Test where import Char ... then you don't have to load it in Hugs. When you load it, I think (could be wrong, I'm not a big hugs guy) it's clearing the fact that you loaded Test. On Thu, 28 Apr 2005, Daniel Carrera wrote:
Alright, I have what I believe must be a simple question. As one of the exercises for the Haskell tutorial I got I have to implement an alternative to the 'map' function.
This is what I have:
----------------------------- my/prompt $ cat Test.hs module Test where
my_map p [] = [] my_map p (x:xs) = p x : my_map p xs my/prompt $ hugs
[snip]
Hugs.Base> :l Test Test> :also Char Char> map toUpper "Hello" "HELLO" Char> my_map toUpper "Hello" ERROR - Undefined variable "my_map" -----------------------------
I can define other functions now (e.g. Fibonacci, length of a list). So I'm not sure why I'm doing wrong here. Even if my syntax is wrong in some way, the function should be defined.
I would be grateful if anyone could point out my error.
Cheers, Daniel. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume

Daniel Carrera wrote:
Alright, I have what I believe must be a simple question. As one of the exercises for the Haskell tutorial I got I have to implement an alternative to the 'map' function.
This is what I have:
----------------------------- my/prompt $ cat Test.hs module Test where
my_map p [] = [] my_map p (x:xs) = p x : my_map p xs my/prompt $ hugs
[snip]
Hugs.Base> :l Test Test> :also Char Char> map toUpper "Hello" "HELLO" Char> my_map toUpper "Hello" ERROR - Undefined variable "my_map"
Hugs can't find your version of "my_map" because it is sitting in the "Char" module (notice the Char> prompt vs. Test>). You could fully qualify the function name (Test.my_map toUpper "Hello"), or you might want to add "import Char" to your source file. Something like... $ cat test.hs module Test where import Char my_map p [] = [] my_map p (x:xs) = p x : my_map p xs $ hugs __ __ __ __ ____ ___ || || || || || || ||__ Hugs 98: Based on the Haskell 98 ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2003 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Report bugs to: hugs-bugs@haskell.org || || Version: November 2003 _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Prelude> :l test.hs Test> my_map toUpper "Hello" "HELLO" Test>
participants (6)
-
Cale Gibbard
-
Daniel Carrera
-
Daniel Fischer
-
Greg Buchholz
-
Hal Daume III
-
Ross Paterson