Haskell error: not in scope. What does it mean?

Today I started work in haskell, and all the functions that I perform on ghci display this message. I just want to know why this is happening. I know there are many questions about this, but this is a simple case, and I need to understand this error at the beginning

function3 :: Int -> [Int]
function3 x = [a | a <- [1..x] mod a x == 0]
+4
source share
1 answer

Has an error occurred while entering a 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 so, you should use multiple lines of input

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

And noted ,beforemod

Alternatively, to improve your workflow, you can save your code in a file and upload to GHCi using : download

$ 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> 
+6
source

Source: https://habr.com/ru/post/1669098/


All Articles