2

I can execute simply operations, like

Hugs> 2+2

for instance. Or any operation, for that matter.

But when it comes to actually trying to define a function, e.g:

occurs :: Eq a => a -> [a] -> Bool 
occurs x l = x `elem` l

Then I get the message:

ERROR - Syntax error in input (unexpected `=')

I also get unexpected `::' in other cases. I'm using WinHugs.

Zeta
  • 103,620
  • 13
  • 194
  • 236
Jason Born
  • 163
  • 1
  • 14

2 Answers2

6

When typing in a function in interactive mode, you need to use let, and you also have to separate lines with a semicolon:

let occurs :: Eq a => a -> [a] -> Bool; occurs x l = x `elem` l
bheklilr
  • 53,530
  • 6
  • 107
  • 163
  • 1
    I copied what you wrote and got: >ERROR - Syntax error in expression (unexpected end of input) – Jason Born Apr 01 '14 at 13:28
  • 2
    @user3482534 It works fine for me, but I'm using GHCi instead of Hugs. I would honestly recommend switching to GHC (and the [Haskell Platform](http://www.haskell.org/platform/)) over Hugs, it has much better support for some of the more modern features, especially considering the last build of Hugs was around 2006. But that is a side note to your problem. Can you try it with curly braces around the definition, like `let { occurs :: ... ; occurs x l = ... }`? – bheklilr Apr 01 '14 at 13:32
  • 1
    @bheklilr is correct. Install Haskell Platform and run with GHCi or .hs files. Hugs is likely to be more of an impedance than a help in learning Haskell. – Alain O'Dea Apr 01 '14 at 14:53
6

You need to save the function in a file (*.hs) and load it via :load <filename>, since the prompt accepts only expressions.

8.5. How do I enter function definitions?

The Hugs prompt only accepts expressions for evaluation. You can create a file containing a Haskell module, and load that (see Section 2.2 for details).

If you want to experiment with function definitions in a REPL environment, I recommend you to use GHCi instead.

Community
  • 1
  • 1
Zeta
  • 103,620
  • 13
  • 194
  • 236