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

Did error happen when you type the function type in 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

Alternatively, for better workflow, you can save your code to a file and load in GHCi using :load

$ 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> 

Leave a Comment

tech