错误 haskell:不在范围内。那是什么意思?

Error haskell: not in scope. What does that mean?

我今天从 Haskell 开始,我在 ghci 上执行的所有功能都显示此消息。我只想知道为什么会这样。 我知道有很多关于这个的问题,但这是一个简单的案例,我需要在开始时理解这个错误

function3 :: Int -> [Int]
function3 x = [a | a <- [1..x] mod a x == 0]

在GHCi中输入函数类型时是否出现错误?

$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Prelude> function3 :: Int -> [Int]

<interactive>:1:1: error:
    Variable not in scope: function3 :: Int -> [Int]
Prelude> 

如果是这样,就得用多行输入

Prelude> :{
Prelude| function3 :: Int -> [Int]
Prelude| function3 x = [a | a <- [1..x], mod a x == 0]
Prelude| :}

并在 mod

之前注明 ,

或者,为了更好的工作流程,您可以将代码保存到文件中,然后使用 :load

加载到 GHCi 中
$ cat tmp/functions.hs 
function3 :: Int -> [Int]
function3 x = [a | a <- [1..x], mod a x == 0]

$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Prelude> :l tmp/functions.hs 
[1 of 1] Compiling Main             ( tmp/functions.hs, interpreted )
Ok, modules loaded: Main.
*Main> :t function3 
function3 :: Int -> [Int]
*Main> 

对我来说,它试图在打开新会话后 :reload 我在 ghci 中的 .hs 文件,但是 :load full_file_name.hs 解决了问题。