open-typerep

Open type representations and dynamic types https://github.com/emilaxelsson/open-typerep

Latest on Hackage:0.6.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Emil Axelsson
Maintained by emax@chalmers.se

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.

comments powered byDisqus