Changes between Version 9 and Version 10 of GhcKinds/PolyTypeable


Ignore:
Timestamp:
Feb 25, 2014 10:23:02 AM (18 months ago)
Author:
dreixel
Comment:

Update text for 7.8, add how to make your code compile again

Legend:

Unmodified
Added
Removed
Modified
  • GhcKinds/PolyTypeable

    v9 v10  
    1 = Kind-polymorphic `Typeable` =
     1= Kind-polymorphic `Typeable`in GHC 7.8 =
    22
    3 The page describes an improved implementation of the `Typeable` class, using polymorphic kinds.  Technically it is straightforward, but it represents a non-backward-compatible change to a widely used library, so we need to make a plan for the transition.
     3The page describes an improved implementation of the `Typeable` class, using polymorphic kinds, available from GHC 7.8.  Technically it is straightforward, but it represents a non-backward-compatible change to a widely used library, so we had to make a plan for the transition.
    44
    5 Relevant tickets we could thereby fix: #5391, #5863.
     5Relevant tickets we fixed: #5391, #5863.
    66
    7 Open question: what are the corresponding changes to `Data.Data`?  See #4896,
     7== The `Typeable` class before 7.8 ==
    88
    9 == The current `Typeable` class ==
    10 
    11 The current `Typeable` class is:
     9Before 7.8, the `Typeable` class was as follows:
    1210{{{
    1311class Typeable (a :: *) where
    1412  typeOf :: a -> TypeRep
    1513}}}
    16 Because it is mono-kinded we also have
     14Because it was mono-kinded we also had
    1715{{{
    1816class Typeable1 (f :: *->*) where
    1917  typeOf1 :: f a -> TypeRep
    2018}}}
    21 and so on up to `Typeable7`.  It's a mess, and we cannot make `Typeable` at all for
     19and so on up to `Typeable7`.  It was a mess, and we couldn't make `Typeable` at all for
    2220type constructors with higher kinds like
    2321{{{
    2422  Foo :: (* -> *) -> *
    2523}}}
    26 See #5391
     24See #5391.
    2725
    28 == The new `Typeable` class ==
     26== The new `Typeable` class, in GHC 7.8 ==
    2927
    3028Having polymorphic kinds lets us say this:
     
    5351}}}
    5452
    55 Now we can give give kind-specific instances:
     53Now the base library code can have kind-specific instances:
    5654{{{
    5755instance Typeable Int where typeRep _ = ...
     
    6058  typeRep _ = ...
    6159}}}
    62 A use of `deriving( Typeable )` for a type constructor `T` would always generate
     60A use of `deriving( Typeable )` for a type constructor `T` always generates
    6361{{{
    6462instance Typable T where typeRep _ = ....
     
    6664i.e. an instance of `T` itself, not applied to anything.
    6765
    68 === Aside ===
    6966
    70 Iavor suggested:
     67== How to make your code compile again ==
     68
     69If you have code involving `Typeable` that fails to compile with 7.8, it might be due to the changes described above. Here's a few things to keep in mind in order to make your code compile again:
     70 
     71  * Users can no longer giving manual instances of `Typeable`; they must be derived.
     72
     73  * Manual instances were often written for datatypes with non kind-`*` arguments. These can now be derived without problems. So if you had, for example:
    7174{{{
    72 class Typeable (a :: k) where
    73   typeRep :: TTypeRep a
     75data Fix f = In (f (Fix f))
     76instance (Typeable1 f) => Typeable (Fix f) where typeOf = ...
     77}}}
     78    you can now simply attach `deriving Typeable` to `Fix`.
    7479
    75 newtype TTypeRep a = TR TypeRep
    76 }}}
     80  * You can still use `typeOf1..7`; they are now just (deprecated) type-specific versions of `typeRep`. But keep in mind that they are no longer methods of a class, as the classes `Typeable1..7` no longer exist.
    7781
    78 Is this perhaps better?
     82  * You can still use `Typeable1..7`; they are now just (deprecated) type synonyms for `Typeable`, fixing the kind of their argument. But keep in mind that they are no longer classes, just type synonyms.
     83
     84  * If all else fails, you could just try replacing your `import Data.Typeable` with `import Data.OldTypeable`. But keep in mind that `OldTypeable` is distinct, and incompatible with the new `Typeable`.
     85
     86  * If you want code that compiles with multiple versions of GHC, you should use CPP. The [http://hackage.haskell.org/package/tagged tagged package on Hackage] is a good example of how to achieve this.
    7987
    8088== A change-over plan ==
     
    92100typeOf1 :: forall t (a :: *). Typeable t => t a -> TypeRep
    93101typeOf1 _ = typeRep (Proxy :: Proxy t)
     102
     103type Typeable1 (a :: * -> *)                               = Typeable a
     104type Typeable2 (a :: * -> * -> *)                          = Typeable a
    94105}}}
    95106
    96107 * Make `deriving( Typeable )` work with whatever `Typeable` class is in scope.  So what it does will be determined by whether you say `import Data.Typeable` or `import Data.OldTypeable`.
    97108
    98 '''I think that means that old programs will continue to work in GHC 7.8''', provided
    99  * You did not mention `Typeable1` etc explicitly
    100  * You used `deriving( Typeable )` to write instances.
    101 
    102109'''In GHC  7.10:'''
    103110  * Remove `Data.OldTypeable`
    104111
     112== Aside ==
    105113
     114Open question: what are the corresponding changes to `Data.Data`?  See #4896.