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

Mar*_*cio 13 haskell ghci

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

function3 :: Int -> [Int]
function3 x = [a | a <- [1..x] mod a x == 0]
Run Code Online (Sandbox Code Playgroud)

wiz*_*zup 21

在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> 
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,则必须使用多行输入

Prelude> :{
Prelude| function3 :: Int -> [Int]
Prelude| function3 x = [a | a <- [1..x], mod a x == 0]
Prelude| :}
Run Code Online (Sandbox Code Playgroud)

,之前注意到了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> 
Run Code Online (Sandbox Code Playgroud)