Note that there are some explanatory texts on larger screens.

plurals
  1. POAnonymous Type Functions
    primarykey
    data
    text
    <p>This is a followup to a previous question: <a href="https://stackoverflow.com/questions/19191348/type-level-map-with-datakinds">Type-level Map with DataKinds</a>, starting with from the two answers it received.</p> <p>My goal is to take a <code>HList</code> of arbitrary types and turn it into a list of related/derived types</p> <pre><code>type family TypeMap (a :: * -&gt; *) (xs :: [*]) :: [*] type instance TypeMap t '[] = '[] type instance TypeMap t (x ': xs) = t x ': TypeMap t xs data HList :: [*] -&gt; * where HNil :: HList '[] HCons :: a -&gt; HList as -&gt; HList (a ': as) </code></pre> <p>When I actually tried to do this with a few types, I ran into a problem. The type-function " argument to TypeMap has to take the <code>HList</code> element type as its last argument and return a new type. This works okay sometimes:</p> <pre><code>test :: HList rqs -&gt; HList (TypeMap ((,) Int) rqs) test HNil = HNil test (HCons x xs) = HCons (3,x) $ test xs </code></pre> <p>But what if I wanted to switch the order of the tuple in the definition of test? My first attempt was to define a type synonym:</p> <pre><code>type RevIntTup b = (b,Int) test2 :: HList rqs -&gt; HList (TypeMap RevIntTup rqs) test2 HNil = HNil test2 (HCons x xs) = HCons (x,3) $ test2 xs </code></pre> <p>But of course, <a href="https://stackoverflow.com/questions/4922560/why-doesnt-typesynonyminstances-allow-partially-applied-type-synonyms-to-be-use">you can't partially apply type synonyms</a>, which would certainly do the trick. Is there any (other) way to achieve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload