I thought I would spend some time this morning trying to learn Haskell. I happen to have downloaded a copy of WinHugs, and it seems to be functioning properly.
Alas, every function definition example I try to use blows up on me.
From: Beginning HaskellÂ
Hugs> myNum :: Int
ERROR - Undefined variable “myNum”
Hugs> square :: Int -> Int
ERROR - Undefined variable “square”
Hugs> square n = n*n
ERROR - Syntax error in input (unexpected `=’)
Hmm, maybe the syntax is different? Looking at the WinHugs documentation, it says it is Haskell 98 compliant, except in some strange ways. Well, there’s always “Haskell in 5 steps”
Hugs> let fac n = if n == 0 then 1 else n * fac (n-1)
ERROR - Syntax error in expression (unexpected end of input)
Hugs> fac n = if n == 0 then 1 else n * fac (n-1)
ERROR - Syntax error in input (unexpected `=’)
Hmmm. Looking further at the Haskell in 5 steps, it seems like maybe I have to write the factorial program seperately, and load it into WinHugs? So I create fac.hs, and put it in:
C:\dev\haskell
C:
My Documents
C:\Program Files\WinHugs\
Can it find it in any of those locations? No.  Even when I use the “Open” command from within WinHugs, it still can find fac.hs, even though I can clearly see it in my file explorer.
So I think that’s enough for one day.
Type
Hugs.Base> let myNum = 7 in myNum
7
Hugs.Base> let square x = x * x in square 7
49
Hugs.Base> let fac n = if n == 0 then 1 else n * fac (n-1) in fac 7
5040
However, most of the things you’ve tried to do are using GHCi syntax. You’ll probably prefer to install GHCi and start there:
$ ghci
Prelude> let myNum = 7
Prelude> myNum
7
Prelude> let square x = x * x
Prelude> square 7
49
Prelude> square 8
64
Prelude> let fac n = if n == 0 then 1 else n * fac (n-1)
Prelude> fac 7
5040
Now say we go and put some code in the file /tmp/A.hs:
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
We can load and run that code in GHCi:
Prelude> :l /tmp/A.hs
*Main> take 10 fibs
[1,1,2,3,5,8,13,21,34,55]
Or Hugs:
Hugs.Base> :l /tmp/A.hs
Main> take 10 fibs
[1,1,2,3,5,8,13,21,34,55]
And off you go!
Comment by Don Stewart — February 27, 2007 @ 3:30 am
Hi,
I wrote WinHugs, so I’m curious to find out what the issue you are having with Open is. You click the “Open” button, browse to the file (whereever it is) and select it. Click the Open button and thats it.
The underlying Hugs provides the let’s etc, so is a bit beyond what I can change, but if there is something that makes Open non-intuative then I’d love to hear about it. If you send an email to haskell-cafe -AT- haskell.org, describing exactly what you did, and what you expected to happen, I’ll definately spot that.
Thanks
Neil
(WinHugs developer)
Comment by Neil Mitchell — February 28, 2007 @ 8:03 pm
Hi Neil,
Thanks for stopping by. While attempting to reproduce this, I discovered what the problem was - it was really fac.hs.txt, but, of course, the .txt extension was hidden. Stupidity on my part, alas.
As far as the language difference, I recognize that this isn’t a trivial fix. At the very least, however, you should make it clear, maybe a dialog or some such when you first start it up, that Haskell apparently has multiple variant dialects, and the example programs that work in one won’t work in another.
Let’s face it - if you were in my shoes, and you wanted to learn this language you’d seen everyone raving about called “ShoeHorse”. So you download a program called WinShod, that indicates it is based on the ShoeHorse 98 standard. And then you proceed to ShoeHorse.org and attempt to use some of the tutorials there to write some programs.
If those programs don’t work, and there’s no indication that there are different dialects, you’d get pretty frustrated pretty quickly.
To be clear: I’m not blaming you for the behavior, the dialects or anything else. I’m just saying, as a casual “toe dipper”, this experience was far less friendly than I would have expected, and I can only imagine how many other people have had similar, or worse experiences and just haven’t written about them.
jb
Comment by jb — February 28, 2007 @ 8:25 pm