logo       

RE: deriving problem: msg#00016

lang.haskell.glasgow.bugs

Subject: RE: deriving problem

The deriving clause is trying to come up with an instance declaration
that looks like

instance ??? => Show (S r) where ....

What should the "???" be? Well, to show an S we have to show an (r
String) and a (r Int), so they plainly need to be in class Show. But
instance declarations must have only type variables in their context
(lest we stray into undecidability). So this is not legal Haskell 98
instance (Show (r Int), Show (r String)) => Show (S r ) where...
Hence the message.

I'm not sure what Hugs is doing. Maybe it just generates the above
instance declaration and hopes for the best.

The instances you give aren't legal H98 either, of course.

Simon

| -----Original Message-----
| From: Dean Herington [mailto:heringto@xxxxxxxxxx]
| Sent: 08 March 2003 19:09
| To: glasgow-haskell-bugs@xxxxxxxxxxx
| Subject: deriving problem
|
| The attached program works under hugs -98 but fails with GHC 5.04.2
| with:
|
| --------
| Params2b.hs:6:
| No instance for `Show (r String)'
| When deriving the `Show' instance for type `S'
|
| Params2b.hs:6:
| No instance for `Show (r Int)'
| When deriving the `Show' instance for type `S'
| --------
|
| If the `deriving` clause for `newtype S r` is replaced by the
| commented-out instance declarations, both systems are happy.
|
| Did I just get lucky with Hugs, or is GHC in error?
|
| -- Dean
|
| --------
|
| {-# OPTIONS -fglasgow-exts #-}
|
| class ByField s where
| byField :: (forall a. r1 a -> r2 a) -> s r1 -> s r2
|
| newtype S r = S (r Int, r String)
| deriving Show
| {-
| instance Show (S Id) where
| show (S s) = "S " ++ show s
| instance Show (S []) where
| show (S s) = "S " ++ show s
| -}
|
| instance ByField S where
| byField f (S (i,s)) = S (f i,f s)
|
| newtype Id a = Id a
| deriving Show
|
| twice :: S Id -> S []
| twice = byField (\(Id x) -> [x,x])
|
| main = do print s; print (twice s)
| where s = S (Id 3, Id "abc")
|
|
| _______________________________________________
| Glasgow-haskell-bugs mailing list
| Glasgow-haskell-bugs@xxxxxxxxxxx
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise