Consider what follows to be my code
import Data.Char
import Data.List
-- square
square :: Int -> Int
square n = n * n
Although this square functions looks neat and clear, when I run it
ghci ./square.hs
It returns
[1 of 1] Compiling Main ( ./LabSheet1-solns.hs, interpreted )
./LabSheet1-solns.hs:5:1:
parse error on input `square'
Failed, modules loaded: none.
There should probably be something wrong with my interpreter.
I am running on OS X 10.8.1
$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 7.4.2
Any clue?
Your
importstatements are indented by one space. This basically sets “one space” as the base indentation level for the file. Since your definition ofsquareis not indented by one space, you get a syntax error.To fix the problem, either indent all lines by one space, or preferably don’t indent the
importstatements.