Haskell ghci变量不在范围内

jks*_*end 2 haskell ghci sublimetext3

你好,我使用 sublime text 3 和我的 cmd shell 和 ghci。我在 st3 中编写了以下函数:

testing :: Int -> Bool
testing 0 = True
testing 1 = False
testing n = testing(n mod 2)
Run Code Online (Sandbox Code Playgroud)

我知道 haskell 提供了一个 even 函数,但我们必须编写我们自己的 even 函数,所以我想出了这个。当我将文件加载到 ghci 中时:

:cd <pathtofile>
:l myfile.hs
Run Code Online (Sandbox Code Playgroud)

并尝试执行我的功能

testing 10
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

 Variable not in scope: testing :: t0 -> t
Run Code Online (Sandbox Code Playgroud)

我可能应该提到 testing :: Int -> Bool 使用斐波那契函数共享文件,但这不应该是问题吧?任何帮助表示赞赏!

ElB*_*ulP 5

n mod 2 是错误的语法,这里有两种可能性:

  • mod n 2
  • n `mod` 2

  • 是的,经过一些重新启动和重新加载后,还更改了模组,现在一切正常了,谢谢! (2认同)