terminating instances
Ross Paterson
ross at soi.city.ac.uk
Mon Apr 3 06:53:05 EDT 2006
GHC 6.4 has rather conservative constraints on instances to guarantee
termination. GHC 6.5 has more liberal constraints; see
http://haskell.galois.com/cgi-bin/haskell-prime/trac.cgi/wiki/FlexibleInstances
Unfortunately instances generated by newtype-deriving need not satisfy
either of these constraints (but the newtypes are required to be
non-recursive). I can't construct a problem example for the 6.4 rules
(but nor is there an obvious termination ordering). However the following
is non-terminating (caught by the depth limit) for GHC 6.5:
class C a where foo :: a -> Bool
-- instance C (f (Maybe a) a a) => C (Bar f a)
newtype Bar f a = Bar (f (Maybe a) a a) deriving C
instance C (Bar (,,) a) => C (a,b,c) where
foo (a,b,c) = foo (Bar (Just a,a,a))
f = foo ('a', 'b', 'c')
More information about the Haskell-prime
mailing list