@hackage open-typerep0.5

Open type representations and dynamic types

This package uses Data Types à la Carte to provide open type representations and dynamic types/coercions for open type universes.

Example 1 (dynamic types):

type MyUniverse = IntType :+: BoolType

hlist :: [Dynamic MyUniverse]
hlist = [toDyn True, toDyn (1 :: Int)]
*Main> hlist
[True,1]

Note that if we were using Data.Dynamic, it would just print

[<<Bool>>,<<Int>>]

Example 2 (dynamically typed addition):

addDyn :: (TypeEq ts ts, PWitness Num ts ts) => Dynamic ts -> Dynamic ts -> Maybe (Dynamic ts)
addDyn (Dyn ta a) (Dyn tb b) = do
    Dict <- typeEq ta tb
    Dict <- pwit pNum ta
    return (Dyn ta (a+b))

Data.Dynamic could only do this monomorphically, for one Num type at a time.