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:igloo@earth.li] | Sent: 14 December 2001 21:29 | To: haskell@haskell.org | 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 | Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell |
On Mon, Dec 17, 2001 at 08:57:28AM -0800, Simon Peyton-Jones wrote:
Well, Foo *is* an instance of Num, so a correct Haskell impl should pick that instance always.
I was looking at what the implementations would allow, the module wasn't supposed to be useful.
Since you don't define the fromInteger method in the instance decl, you get a runtime error.
I expected this, I included it as in some cases I *didn't* et a runtime error though.
I don't know what you expect the [Foo] and Foo -> Int defaults to do.
Let me try to clarify what I was asking: What is a monotype? For example, is "[Foo]" a monotype and is "Foo -> Int" a monotype? The context free grammar implies that a monotype is identical to a type, in which case why is a different name used? The rest was to attempt to highlight some inconsistencies in the implementations. Thanks Ian
participants (2)
-
Ian Lynagh -
Simon Peyton-Jones