I just began learning haskell a few days ago and I started with the first problem in "99 haskell questions" a few minutes ago.
The first one is fairly simple, to get the last element from a list. I was trying out various ways to solve, but I encountered the above error when I tried this little guy:
getLast = foldr1 $ flip const
I understand that this error occurs due to haskell being unable to infer the type of the function getLast and all I need to do is add an explicit type annotation for getLast.
But strangely, if I write the above code in GHCi, it works! How is this possible? Is somehow GHCi Clairvoyant and be able to deduce types now?
What are the major differences between writing a code directly in GHCi and writing haskell code in a .hs file and loading it?