haskell-distributed/rank1dynamic — pull request #6 by facundominguez (2014-07-28 13:26:08+00:00)
Title: Support for higher-kinded types in rank1dynamic

These patches allow Data.Rank1Typeable to represent type variables with kinds other than `*`. This is done by using the magical kind-polymorphic `GHC.Exts.Any` when representing these variables.

For instance, previously, it was not possible to represent the type of

```Haskell
return :: Monad m => a -> m a
```
Even by reifying the constraint as
```Haskell
data MonadDict m = Monad m => MonadDict

returnD :: MonadDict m -> a -> m a
returnD MonadDict = return
```
one still could not write the type as
```Haskell
returnD :: MonadDict ANY -> ANY1 -> ANY ANY1
```
because in the above `ANY` is expected to have kind `* -> *` where the implementation would only allow `*`. Now, such a type signature is valid after these patches.

For convenience, we introduce the functions

```Haskell
reifyConstraints :: (c => a) -> Dict c -> a
abstractConstraints :: c => (Dict c -> a) -> a
```

The `Dict` datatype comes from @ekmett’s [constraints](http://hackage.haskell.org/package/constraints) package and enables reifying and abstracting away constraints in an expression:
```Haskell
reifyConstraints return :: Dict (Monad m) -> a -> m a

abstractConstraints
(reifyConstraints return :: Dict (Monad m) -> a -> m a)
:: Monad m => a -> m a
```