Haskell ghci 变量不在范围内

标签 haskell sublimetext3 ghci

你好,我使用 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/

相关文章:

haskell - `_` 函数参数的评估(或根本没有)?

sublimetext3 - Sublime Text 3 中不能插入反斜杠

plugins - 侧边栏增强插件已安装但不起作用

node.js - Sublime Text 在运行 Node js 代码时抛出 python 权限

haskell - 我如何在 GHCi 中抑制 "Failed, modules loaded:"?

haskell - 无法创建 Num 的派生实例

haskell - 在 .ghci 文件中定义多行函数

haskell - 秒差距:回溯不起作用

haskell - 如何实现 mapAccumM?

haskell - 具有代数类型的镜头包