haskell - Constrained heterogeneous list -
i searched hackage , couldn't find following seems simple , useful. there library contains sort of data type?
data hlist c (:-) :: c => -> hlist c nil :: hlist c
all hlists found have type, , weren't constrained.
if there isn't i'll upload own.
i'm not sure data type useful...
if want
a
existentially qualified, think should use regular lists. more interesting data type hereexists
, although i'm there variants of onpackagehackage already:data exists c exists :: c => -> exists c
then,
hlist c
isomorphic[exists c]
, can still use of usual list based functions.on other hand, if don't want
a
in(:-) :: c => -> hlist c
existentially qualified (having such sort of defies point ofhlist
), should instead define following:data hlist (as :: [*]) (:-) :: -> hlist -> hlist (a ': as) nil :: hlist '[]
then, if want require entries of
hlist
satisfyc
, can make type class witness injectionhlist as
[exists c]
instance resolution works if types inhlist
satisfy constraint:class forallc c aslist :: hlist -> [exists c] instance forallc '[] c aslist nil = [] instance (c a, forallc c) => forallc (a ': as) c aslist (x :- xs) = exists x : aslist xs
Comments
Post a Comment