Create a list of values from type-level list

Viewed 1139

I have a type-level list like this

data TList (ixs :: [*]) (f :: * -> *) where
  TNil  :: TList '[] f
  (:-:) :: f ix -> TList ixs f -> TList (ix ': ixs) f

And I'm trying to generate a new TList using an existing one. The idea is to have a function

genTList :: TList ixs f -> t -> TList ixs g

where 't' is some function able to construct a value of type 'g x' where 'x' is one of types form the list 'ixs'.

So that given

data Foo x

and (some kind of)

generate :: forall x . Bar x

I could get something like this

genTList (Foo Int :-: Foo String) generate = Bar :-: Bar

So essentially for every item 'x' in the type list I want to have a type 'Bar x' and also construct its value with parameterless constructor, because I know that 'Bar x' doesn't have constructor parameters.

I tried to implement something (https://gist.github.com/lolepezy/30820595afd9217083c5ca629e350b55) but it wouldn't typecheck (reasonably).

So how should I approach the problem?

1 Answers
Related