[TYPES] A show-stopping problem for modular type classes?

oleg@okmij.org oleg at okmij.org
Tue Oct 13 03:35:34 EDT 2009


The topic of local instance declarations has been discussed 
in Sec 6.1 of the HW 2004 paper
	http://www.cs.rutgers.edu/~ccshan/prepose/prepose.pdf

We have proposed a restriction that a local instance must mention an
opaque type. That means your example must be written as

    data T a = T Int

    module S0 : sig val s : Set T end = struct
       type t -- abstract
       instance Ord (T t) where ...

       val s = Set.insert ...


Now, S0.s will have type (T some_t1) and S1.s will have type (T
some_t2), which are of course incompatible. Within module S0, one may
freely use the locally-defined Ord, along with any globally defined
Ord instances. There cannot be any overlap. One may regard the
technique of our HW 2004 paper as giving a translation into ordinary
Haskell (Haskell98 + rank-2 types).



More information about the Types-list mailing list