Confused about default

Ian Lynagh igloo@earth.li
Fri, 14 Dec 2001 21:28:30 +0000


Hi all

I am rather confused about default.

In section 4.3.4 the report says
    "each ti must be a monotype for which Num ti holds"
but according to grep this is the only place "monotype" appears in the
report.

If I have the module

    module TT (Foo(..)) where

    default (Foo, [Foo], Foo -> Int)

    data Foo = Foo deriving (Eq, Show)

    instance Num Foo where {}
    instance (Eq a, Show a) => Num [a] where {}
    instance Eq (a -> b) where {}
    instance Show (a -> b) where {}
    instance Num (a -> b) where {}

then hugs accepts it and
    TT> 5

    Program error: Undefined member: fromInteger

ghc accepts it and
    TT> 5
    5

nhc tells me

    Error when renaming::
    Illegal type in default at 4:17

If I remove all the list and function stuff then hi says
    TT> 5
    5

If I have a
    main = putStrLn $ show 5

then nhc gives me
    TT> main
    No default definition for class method fromInteger

and ghci gives me
    Main> main
    *** Exception: TT.lhs:8: No instance nor default method for class
    operation PrelNum.fromInteger


It seems to me that hugs is in the right with it's handling of 5, but I
am not sure who is wrong with default ([Foo]) or (Foo -> Int).


Finally, the context free grammar doesn't currently enforce the
restriction that only one default declaration be given. Fixing it would
make rather a mess, though.


Ian