piggyback
piggyback

Reputation: 9244

Simple haskell program doesnt compile with GHCi

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?

Upvotes: 1

Views: 215

Answers (2)

sepp2k
sepp2k

Reputation: 370082

Your import statements are indented by one space. This basically sets "one space" as the base indentation level for the file. Since your definition of square is 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 import statements.

Upvotes: 10

applicative_functor
applicative_functor

Reputation: 4976

Fix your indentation:

import Data.Char
import Data.List

-- square
square :: Int -> Int
square n = n * n

Upvotes: 5

Related Questions