Questions tagged [multiline-repl-definition]
5 questions
191
votes
7 answers
How to define a function in ghci across multiple lines?
I'm trying to define any simple function that spans multiple lines in ghci, take the following as an example:
let abs n | n >= 0 = n
| otherwise = -n
So far I've tried pressing Enter after the first line:
Prelude> let abs n | n >= 0 =…

Peter McG
- 18,857
- 8
- 45
- 53
162
votes
5 answers
Multi-line commands in GHCi
I am having problem in entering multi-line commands in ghci.
The following 2-line code works from a file:
addTwo :: Int -> Int -> Int
addTwo x y = x + y
But when I enter in ghci, I get an error:
:1:1: error:
Variable not in scope:…

R71
- 4,283
- 7
- 32
- 60
1
vote
0 answers
Haskell compiler's errors on simple lists' code
I'm trying to learn Haskell, so I installed Haskell Stack tool following the instructions at https://docs.haskellstack.org/en/stable/install_and_upgrade/.
Now I was trying to work with lists and I wrote a simple map function on ghci compiler
myMap f…

Flora Angileri
- 23
- 4
1
vote
1 answer
Missing pattern in inserts function
I have this function inserts where
inserts 1 [2,3] = [[1,2,3],[2,1,3],[2,3,1]]
here's the definition (straight from Algorithm Design with Haskell by Bird and Gibbons)
inserts :: a -> [a] -> [[a]]
inserts x [] = [[x]]
inserts x (y:ys) = (x:y:ys) :…

JaviRdrgz
- 21
- 3
1
vote
2 answers
Non-exhaustive patterns in function len
I'm writing this function len which calculates the length of a list in GHCi.
len [] = 0
len [x] = 1
len (x:xs) = 1 + len xs
I tried to call the function with [] as the argument but the error Exception: Non-exhaustive patterns in function len hit…

Py thon
- 23
- 3