[英]Error haskell: not in scope. What does that mean?
I started with Haskell today and all the functions I perform on ghci display this message.我今天开始使用 Haskell,我在 ghci 上执行的所有功能都显示此消息。 I just want to know why this is happening.
我只想知道为什么会这样。 I know there are a lot of questions about this, but this is a simple case and I need to understand this error in the beginning
我知道有很多关于这个的问题,但这是一个简单的案例,我需要在开始时理解这个错误
function3 :: Int -> [Int]
function3 x = [a | a <- [1..x] mod a x == 0]
Did error happen when you type the function type in GHCi?在 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>
If it is the case, you have to use multiple line input如果是这种情况,则必须使用多行输入
Prelude> :{
Prelude| function3 :: Int -> [Int]
Prelude| function3 x = [a | a <- [1..x], mod a x == 0]
Prelude| :}
And noted ,
before mod
并注意到
,
在mod
之前
Alternatively, for better workflow, you can save your code to a file and load in GHCi using :load或者,为了更好的工作流程,您可以将代码保存到文件并使用: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>
对我来说,它试图在打开一个新会话后在 ghci 中:reload
我的.hs
文件,但是执行:load full_file_name.hs
解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.