haskellghcleksah

haskell code compiles on leksah but not ghc


As the question states, I have some that compiles in leksah but does not compile using ghc --make filename.hs

The code:

module Main (
    main
) where

pair a b = (Pair (a, b))

newtype Pair a b = Pair (a,b)  deriving (Eq,Show)

instance (Num a,Num b) => Num (Pair a b) where
   Pair (a,b) + Pair (c,d) = Pair (a+c,b+d)
   Pair (a,b) * Pair (c,d) = Pair (a*c,b*d)
   Pair (a,b) - Pair (c,d) = Pair (a-c,b-d)
   abs    (Pair (a,b)) = Pair (abs a,    abs b) 
   signum (Pair (a,b)) = Pair (signum a, signum b) 
   fromInteger i = Pair (fromInteger i, fromInteger i)

main = do   
            a <- return (pair 1 3)   
            print a
            print "haha"  
            print 3.2  
            print [3,4,3]  

Is there an option I need to invoke to make it run with ghc --make?

Disclaimer: I did not make the pair newtype.

Edit:

When using ghc --make Bignumber.hs (Bignumber.hs is the filename) the output is

[1 of 1] Compiling Main             ( BigNumber.hs, BigNumber.o )

BigNumber.hs:20:13: parse error on input `print'

Solution

  • Check your indentation: maybe you're mixing tabs and spaces in a way that ghc interprets differently than leksah? I don't see another explanation for a parse error at print.