Changes between Version 7 and Version 8 of KindFact


Ignore:
Timestamp:
Mar 10, 2011 1:23:08 AM (3 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • KindFact

    v7 v8  
    4848}}} 
    4949 
     50== Discussion == 
    5051 
     52`Fact` synonyms appear to overlap with superclases.  For example one could say 
     53{{{ 
     54class (Read x, Show x) => Stringy x where {} 
     55}}} 
     56But there are significant differences 
     57 * Using the class mechanism forces you to give an `instance` declaration too.  Perhaps something like 
     58{{{ 
     59instance (Read x, Show x) => Stringy x where {} 
     60}}} 
     61 This is painful duplication, and (worse) there is little to stop you writing an overlapping instance later.  At least, looking at the instance doesn't tell you that no overlapping instance is intended. 
     62 
     63 * The type family mechamism gives new power.  For example, consider the celebrated collection example: 
     64{{{ 
     65class Collection c where 
     66  type family X c :: * -> Fact 
     67  empty :: c a 
     68  insert :: (X c) => c a -> a -> c a 
     69 
     70instance Collection [] where 
     71  type instance X [] a = Eq a 
     72  insert xs x = ... 
     73 
     74instance Collection Data.Set where 
     75  type instance X Data.Set a = Ord a 
     76  insert s x = ... 
     77}}} 
     78  See [http://research.microsoft.com/en-us/um/people/simonpj/papers/collections.ps.gz Bulk types with class]. 
    5179 
    5280== Bikeshed discussion of nomenclature ==