开发者

WinHugs - how to declare a variable and a function

I've downloaded Wi开发者_如何转开发nHugs 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜