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?