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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With