Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinHugs - how to declare a variable and a function

Tags:

haskell

I've downloaded WinHugs 2 hours ago and still can't figure out how to declare simple things. I'm trying to follow the book "7 languages in 7 weeks", but stuff like let x = 10 and double x = x * 2 gives syntax errors.

like image 436
Sara Darcy Avatar asked Aug 08 '11 14:08

Sara Darcy


2 Answers

I'm not 100% sure what you're trying to do that doesn't work. You can't declare bindings in a WinHugs session, you can only evaluate full expressions. So you could do things like let x = 10 in x * x + x, but you can't say let x = 10 in an interactive session. In other words, you can't make the declaration 'stick'.

To get around this, either put your declarations in a .hs file and load it in WinHugs, or use GHCi instead (this is the better option, in my opinion - WinHugs is pretty dated). You can install GHCi by downloading Haskell Platform.

like image 153
yatima2975 Avatar answered Oct 31 '22 13:10

yatima2975


in winhugs the following gives a syntax error

let double x = x * 2

but the following works:

let double x = x * 2 in double 10

however in ghc they have the interactive environment ghci where everything works

let double x = x * 2

works

double 10

works

this link explains how to work with ghci environment: https://downloads.haskell.org/~ghc/7.2.2/docs/html/users_guide/interactive-evaluation.html

One minor issue is that on windows you need the presence of cygwin - otherwise ghci as compiled for windows will not work.

like image 1
MichaelMoser Avatar answered Oct 31 '22 14:10

MichaelMoser