由于语法错误,我无法在Haskell上执行任何操作 [英] I can't do anything on Haskell due to syntax errors
问题描述
我可以执行简单的操作,例如
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
然后我收到消息:
ERROR - Syntax error in input (unexpected `=')
在其他情况下,我也得到unexpected `::'
.我正在使用WinHugs.
I also get unexpected `::'
in other cases. I'm using WinHugs.
推荐答案
由于提示仅接受表达式,因此您需要将函数保存在文件(* .hs)中并通过:load <filename>
加载.
You need to save the function in a file (*.hs) and load it via :load <filename>
, since the prompt accepts only expressions.
拥抱"提示仅接受用于求值的表达式.您可以创建一个包含Haskell模块的文件,然后加载该文件(请参见第2.2节以获取详细信息).
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).
如果要在REPL环境中尝试使用函数定义,建议您改用GHCi.
If you want to experiment with function definitions in a REPL environment, I recommend you to use GHCi instead.
这篇关于由于语法错误,我无法在Haskell上执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!