你好,我使用 sublime text 3 和 ghci 的 cmd shell。 我在 st3 中编写了以下函数:
testing :: Int -> Bool
testing 0 = True
testing 1 = False
testing n = testing(n mod 2)
我知道haskell提供了偶函数,但我们必须编写自己的偶函数,所以我想出了这个。当我将文件加载到 ghci 时:
:cd <pathtofile>
:l myfile.hs
并尝试使用
执行我的函数testing 10
我收到此错误:
Variable not in scope: testing :: t0 -> t
我可能应该提到测试::Int -> Bool 与斐波那契函数共享文件,但是 这不应该是问题吧? 任何帮助表示赞赏!
最佳答案
n mod 2
是错误的语法,这里有两种可能性:
mod n 2
n `mod` 2
关于Haskell ghci 变量不在范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61457913/