I can't do anything on Haskell due to syntax errors

若如初见. 提交于 2019-12-11 01:40:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!