Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tryhaskell.org support definitions?

Tags:

haskell

I try using "let" to define an expression definition, but all I get is errors.

> let double x = x * x
not an expression: `let double x = x * x'

Is there a special command I have to use or does the javascript compiler not support this functionality?

like image 799
Jonathan Dunlap Avatar asked Jan 13 '12 22:01

Jonathan Dunlap


Video Answer


1 Answers

Indeed, it does not support definitions; presumably since it's only intended as a basic introduction, and probably maintains no state between lines. As implied by its use of hint, it simply evaluates expressions. Also unlike GHCi, it doesn't attempt to execute IO actions (thankfully!), and simply attempts to print them instead (which fails, as IO actions don't have a Show instance).

You can, however, do let square x = x * x in square 42 on a single line.

By the way, Try Haskell doesn't use a JavaScript Haskell compiler or anything like that; it communicates with a server to evaluate the expressions you input.

All in all, it's a neat proof of concept, and a great initial hook to get people interested in Haskell, but for any kind of real use it's not suited in the least compared to something like GHCi.

like image 97
ehird Avatar answered Sep 28 '22 06:09

ehird