Changes between Version 7 and Version 8 of NewtypeWrappers


Ignore:
Timestamp:
Jun 28, 2013 10:36:05 AM (10 months ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewtypeWrappers

    v7 v8  
    197197data NT a b -- abstract 
    198198coerce :: NT a b -> a -> b 
    199 refl :: NT a a 
    200 sym :: NT a b -> NT b a 
    201 trans :: NT a b -> NT b c -> NT a c 
     199refl   :: NT a a 
     200sym    :: NT a b -> NT b a 
     201trans  :: NT a b -> NT b c -> NT a c 
    202202}}} 
    203203and the intention that `NT a b` is a witness that `a` and `b` have the same representation and that `coerce n` has zero runtime cost. 
     
    212212 
    213213This solves the abstraction problem for `Data.Map`: The library author only exports `NT a b -> NT (Map k a) (Map k b)`, but not NT a b -> NT (Map a v) (Map b v)`. 
     214 
     215All this amounts to exposing explicit System-FC coercions to the programmer; and that is precisely what we want to do. 
     216 * Explicit, because `Age` and `Int` really are different types, and so we can't silently convert between them. 
     217 * Explicit, so that we can control precisely which coercions are available (via export lists), and thus control abstraction. 
    214218 
    215219Of course with an `NT` data type, it is possible to define this type class, e.g.