Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GHCi的Haskell初学者错误_Haskell - Fatal编程技术网

GHCi的Haskell初学者错误

GHCi的Haskell初学者错误,haskell,Haskell,我正在Mac上试用Haskell,令我惊讶的是,当我定义一个函数时,出现了一个错误: Prelude System.IO> :set prompt "ghci> " ghci> addMe :: Int -> Int -> Int <interactive>:11:1: error: Variable not in scope: addMe :: Int -> Int -> Int ghci> Prelude System.

我正在Mac上试用Haskell,令我惊讶的是,当我定义一个函数时,出现了一个错误:

Prelude System.IO> :set prompt "ghci> "
ghci> addMe :: Int -> Int -> Int

<interactive>:11:1: error:
    Variable not in scope: addMe :: Int -> Int -> Int
ghci>
Prelude System.IO>:设置提示“ghci>”
ghci>addMe::Int->Int->Int
:11:1:错误:
变量不在范围内:addMe::Int->Int->Int
ghci>

如何在ghci上定义函数?

如果要在ghci中的定义中添加类型签名,可以使用多行输入,如中所述,通过
:set+m
:{…:}
,或使用分号来指定它,如中所述:

mulme x y = [x*y| x /= 0, y/= 0]; mulme :: Int -> Int -> [Int]

使用多行输入或显式分号,如我所示,我发现将所有定义放在一个文件中更容易,然后是代码>:加载< /代码>到GHCI。它将直接在解释器中键入的直接反馈经验与适当源文件的结构和备份功能相结合。请注意,我们通常使用
Maybe
,而不是始终最多包含一个元素的列表。通过这样做,上面定义的右侧可能会变成
,如果(x/=0&&y/=0),那么就只有(x*y)了,其他什么都没有。