1

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 [] = []
myMap f (x:xs) = (f x):myMap f xs

Then i tried to test it with a square function, but something went wrong

square x = x^2
myMap square [1,2,3]
[1,4,9*** Exception: <interactive>:2:1-33: Non-exhaustive patterns in function myMap

I tried to execute this code with the interpreter, so I created an .hs file which contains both myMap and square function definitions, then loaded with command

:l file_name.hs

And now the same test is successful. Why does this happen? What's wrong with compiling? I thought that maybe I didn't install it correctlly, but I'm unable to find what could have gone wrong.. can someone please help me?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • unfortunately it doesn't.. i tried to rewrite myMap but I still get the same error – Flora Angileri Feb 07 '21 at 14:10
  • 2
    you don't need to re-write it. you need to reenter it at the prompt: first `:{`, newline, then the definition's lines, one by one, then `:}`. or, use the source file as you did. – Will Ness Feb 07 '21 at 14:20

0 Answers0