问题
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.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/22787186/i-cant-do-anything-on-haskell-due-to-syntax-errors