Confused about default

Simon Peyton-Jones simonpj@microsoft.com
Mon, 17 Dec 2001 08:57:28 -0800


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]=20
| Sent: 14 December 2001 21:29
| To: haskell@haskell.org
| Subject: Confused about default
|=20
|=20
|=20
| Hi all
|=20
| I am rather confused about default.
|=20
| 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"=20
| appears in the report.
|=20
| If I have the module
|=20
|     module TT (Foo(..)) where
|=20
|     default (Foo, [Foo], Foo -> Int)
|=20
|     data Foo =3D Foo deriving (Eq, Show)
|=20
|     instance Num Foo where {}
|     instance (Eq a, Show a) =3D> Num [a] where {}
|     instance Eq (a -> b) where {}
|     instance Show (a -> b) where {}
|     instance Num (a -> b) where {}
|=20
| then hugs accepts it and
|     TT> 5
|=20
|     Program error: Undefined member: fromInteger
|=20
| ghc accepts it and
|     TT> 5
|     5
|=20
| nhc tells me
|=20
|     Error when renaming::
|     Illegal type in default at 4:17
|=20
| If I remove all the list and function stuff then hi says
|     TT> 5
|     5
|=20
| If I have a
|     main =3D putStrLn $ show 5
|=20
| then nhc gives me
|     TT> main
|     No default definition for class method fromInteger
|=20
| and ghci gives me
|     Main> main
|     *** Exception: TT.lhs:8: No instance nor default method for class
|     operation PrelNum.fromInteger
|=20
|=20
| It seems to me that hugs is in the right with it's handling=20
| of 5, but I am not sure who is wrong with default ([Foo]) or=20
| (Foo -> Int).
|=20
|=20
| Finally, the context free grammar doesn't currently enforce=20
| the restriction that only one default declaration be given.=20
| Fixing it would make rather a mess, though.
|=20
|=20
| Ian
|=20
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20