<div dir="ltr">> Can you be a bit more precise about what you are doing? Constructing<br><div>> core like this is quite hairy.</div><div><br></div><div>I'm modifying TcGenGenerics to use an experimental representation type that leverages ConstraintKinds (and thus constraint tuples) in its type. The function I'm modifying is tc_mkRepTy [1], which constructs the Core Type that's used for Rep/Rep1 in derived Generic instances.</div><div><br></div><div>> The "tuple" part doesn't really exist in core<br></div><div><br></div><div>Sure it does! It does in this code, at least:</div><div><br></div><div> data Foo c a where<br> MkFoo :: c => a -> Foo c a<br> <br> f :: Foo (Eq a, Show a) -> String<br> f (MkFoo x) = show x<br></div><div><br></div><div>According to ghci -ddump-simpl, that gives you the following (unoptimized) Core:<br></div><div><br></div><div> f :: forall a. Foo (Eq a, Show a) a -> String<br> f = \ (@ a_a2RQ)<br> (ds_d2S2 :: Foo (Eq a_a2RQ, Show a_a2RQ) a_a2RQ) -><br> case ds_d2S2 of { MkFoo $d(%,%)_a2RS x_a2Ry -><br> show<br> @ a_a2RQ<br> (GHC.Classes.$p2(%,%) @ (Eq a_a2RQ) @ (Show a_a2RQ) $d(%,%)_a2RS)<br> x_a2Ry<br> }<br></div><div><br></div><div>Notice the $d(%,%)_a2RS and $p2(%,%) bits, which correspond to a constraint tuple dictionary and one of its superclass selectors, respectively.<br></div><div><br></div><div>Ryan S.</div><div>-----</div><div>[1] <a href="http://git.haskell.org/ghc.git/blob/26e9806ada8823160dd63ca2c34556e5848b2f45:/compiler/typecheck/TcGenGenerics.hs#l513">http://git.haskell.org/ghc.git/blob/26e9806ada8823160dd63ca2c34556e5848b2f45:/compiler/typecheck/TcGenGenerics.hs#l513</a><br></div><br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 19, 2018 at 1:09 PM Matthew Pickering <<a href="mailto:matthewtpickering@gmail.com">matthewtpickering@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can you be a bit more precise about what you are doing? Constructing<br>
core like this is quite hairy.<br>
<br>
The "tuple" part doesn't really exist in core, a constraint tuple is<br>
curried. So foo :: (C1 a, C2 a) => ... desugars to `foo = /\ a . \<br>
$dC1 . \$dC2 -> ...`.<br>
<br>
Cheers,<br>
<br>
Matt<br>
<br>
<br>
<br>
On Tue, Jun 19, 2018 at 4:48 PM, Ryan Scott <<a href="mailto:ryan.gl.scott@gmail.com" target="_blank">ryan.gl.scott@gmail.com</a>> wrote:<br>
> Unfortunately, I can't directly use tc_tuple, since I don't have access to<br>
> the Haskell AST forms I need to make that work (I'm constructing everything<br>
> directly in Core). On the other hand, the implementation of tc_tuple does<br>
> have one nugget of wisdom in that it reveals how GHC creates a constraint<br>
> tuple *type constructor*. Namely, `tcLookupTyCon (cTupleTyConName arity)`<br>
> for some `arity`.<br>
><br>
> That's still a bit inconvenient, as `tcLookupTyCon` forces me to work in a<br>
> monadic context (whereas the code I've been working on has been pure up to<br>
> this point). Is there not a pure way to retrieve a constraint tuple type<br>
> constructor?<br>
><br>
> Ryan S.<br>
><br>
> On Tue, Jun 19, 2018 at 10:07 AM Matthew Pickering<br>
> <<a href="mailto:matthewtpickering@gmail.com" target="_blank">matthewtpickering@gmail.com</a>> wrote:<br>
>><br>
>> How about `tc_tuple`?<br>
>><br>
>> On Tue, Jun 19, 2018 at 2:53 PM, Ryan Scott <<a href="mailto:ryan.gl.scott@gmail.com" target="_blank">ryan.gl.scott@gmail.com</a>><br>
>> wrote:<br>
>> > I'm currently working on some code in which I need to produce a Core<br>
>> > Type<br>
>> > that mentions a constraint tuple. I thought that there must surely exist<br>
>> > some way to construct a constraint tuple using the GHC API, but to my<br>
>> > astonishment, I could not find anything. The closest thing I found was<br>
>> > mk_tuple [1], which gives you the ability to make boxed and unboxed<br>
>> > tuples,<br>
>> > but not constraint tuples.<br>
>> ><br>
>> > I then thought to myself, "But wait, PartialTypeSignatures has to create<br>
>> > constraint tuples, right? How does that part of the code work?" To my<br>
>> > horror, I discovered that PartialTypeSignatures actually creates *boxed*<br>
>> > tuples (see mk_ctuple here [2]), then hackily treats them as constraint<br>
>> > tuples, as explained in Note [Extra-constraint holes in partial type<br>
>> > signatures] [3]. I tried reading that Note, but I couldn't follow the<br>
>> > details.<br>
>> ><br>
>> > Is there a simpler way to create a constraint tuple that I'm not aware<br>
>> > of?<br>
>> ><br>
>> > Ryan S.<br>
>> > -----<br>
>> > [1]<br>
>> ><br>
>> > <a href="http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/prelude/TysWiredIn.hs#l810" rel="noreferrer" target="_blank">http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/prelude/TysWiredIn.hs#l810</a><br>
>> > [2]<br>
>> ><br>
>> > <a href="http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/typecheck/TcBinds.hs#l1036" rel="noreferrer" target="_blank">http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/typecheck/TcBinds.hs#l1036</a><br>
>> > [3]<br>
>> ><br>
>> > <a href="http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/typecheck/TcHsType.hs#l2367" rel="noreferrer" target="_blank">http://git.haskell.org/ghc.git/blob/676c5754e3f9e1beeb5f01e0265ffbdc0e6f49e9:/compiler/typecheck/TcHsType.hs#l2367</a><br>
>> ><br>
>> > _______________________________________________<br>
>> > ghc-devs mailing list<br>
>> > <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
>> > <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
>> ><br>
</blockquote></div>