[Haskell-cafe] CRIP: the Curiously Reoccuring Instance Pattern

AntC anthony_clayden at clear.net.nz
Fri Aug 3 13:55:20 CEST 2012


 <oleg <at> okmij.org> writes:

> 
> > I think instead you should have:
> > - abandoned FunDeps
> > - embraced Overlapping more!
> 
> Well, using TypeCast to emulate all FunDeps was demonstrated three
> years later after HList (or even sooner -- I don't remember when
> exactly the code was written):
> 
> http://okmij.org/ftp/Haskell/TypeClass.html#Haskell1
> 

Yikes! Thank you Oleg, more formidable code to get my head round.

> 
> > So here's my conjecture:
> > 1. We don't need FunDeps, except to define TypeCast.
> >    (And GHC now has equality constraints, which are prettier.)
> > 2. Without FunDeps, overlapping works fine.
> > ...
> 
> I agree on point 1 but not on point 2. The example of incoherence
> described in Sec `7.6.3.4. Overlapping instances' of the GHC User
> Guide has nothing to do with functional dependencies.
> 

Well, I meant overlapping as used in HList. But fair point, and goes back to a 
much earlier discussion:
a) Don't switch on IncoherentInstances.
b) Make instance validation 'eager' and 'strict' like Hugs does,
   not 'optimistic'/'lax' like GHC.
   (That is, validate at point of declaration of the instance.)
c) Reject instances that are not explicitly dis-overlapped.

The mechanism for dis-overlap is disequality restraints. So for the multi-
module MyShow example in 7.6.3.4. reject the overlap:
     instance MyShow [T]   -- in module Main is OK, providing
 --  instance MyShow [a]   -- in module Help must be dis-overlapped to
     instance MyShow [a] | a /~ T where ...

The work-in-progress NewAxioms is aiming for something similar, but only for 
type functions. Perhaps in the longer term we use that to build helper 
functions, then banish overlapping type classes?

(I still think that explicitly dis-overlapped instances would be easier to 
understand.)

AntC





More information about the Haskell-Cafe mailing list