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 here exists, although i'm there variants of on package hackage 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 of hlist), should instead define following:

    data hlist (as :: [*])   (:-) :: -> hlist -> hlist (a ': as)   nil :: hlist '[] 

    then, if want require entries of hlist satisfy c, can make type class witness injection hlist as [exists c] instance resolution works if types in hlist 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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -