Well, Foo *is* an instance of Num, so a correct Haskell impl should pick that instance always. Since you don't define the fromInteger method in the instance decl, you get a runtime error.
I don't know what you expect the [Foo] and Foo -> Int defaults to do. GHCi fails to put the correct default decl in place for command-line expressions. This is a known bug which we have not got around to fixing yet Simon | -----Original Message----- | From: Ian Lynagh [mailto:[EMAIL PROTECTED]] | Sent: 14 December 2001 21:29 | To: [EMAIL PROTECTED] | Subject: Confused about default | | | | 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 | | | _______________________________________________ | Haskell mailing list | [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell | _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
