<div dir="ltr">And the point of the "instantiators" is to support generating instances where you also require some value-level definition.  This can now be done via deriving via, except that deriving via will reveal implementation details to users which may be undesirable.  Very roughly (I did not look at how instantiators actually work in the package):<div><br></div><div><font face="monospace">data BoolLike = Trueish | Falseish</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">$($(derive [d|<br>  instance EqViaBijection Bool BoolLike where</font></div><div><font face="monospace">    to True = Trueish</font></div><div><font face="monospace">    to False = Falseish</font></div><div><font face="monospace">    from Trueish = True</font></div><div><font face="monospace">    from Falseish = False</font></div><div><font face="monospace">]|))</font><br><br>and the generated code would be an `Eq` instance, and the bijection used would not be visible to outside users (whereas it is if you use deriving via for this)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 3, 2022 at 8:37 PM Michael Sloan <<a href="mailto:mgsloan@gmail.com">mgsloan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Ah, it allows the mechanism to be open, so if you create a new typeclass you can also declare how to use TH to derive instances.  Roughly (if TH allowed splices in more spots in quotes):<div><br></div><div><font face="monospace">class Tangy a where</font></div><div><font face="monospace">  -- ...</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">instance Deriver (Tangy a) where</font></div><div><font face="monospace">  runDeriver Proxy cxt ty = [d| instance $(cxt) => Tangy $(ty) where {- ... -} |]</font></div><div><br></div><div>Now in some other module I can do:</div><div><font face="monospace"><br></font></div><div><font face="monospace">$($(derive [d| instance Deriving (Tangy X) |]))</font></div><div><br></div><div>The first splice will generate the code that dispatches to the instance, and the next splice will generate the actual output.  This approach can also allow you to use more complex dispatch to the deriver if you wish.  For example, maybe you have a Serializable class that comes with some format type that is openly extensible.  You could define `<font face="monospace">instance Deriver (Serializable Json a)</font>` / `<font face="monospace">instance Deriver (Serializable Yaml a)</font>` etc and `derive` will dispatch to them when interpreting the outer splice.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 3, 2022 at 8:23 PM David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Why the double splice? What about this makes you generate code that when run will generate code?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 3, 2022, 10:10 PM Michael Sloan <<a href="mailto:mgsloan@gmail.com" target="_blank">mgsloan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hmm, the documentation does list 5 bullets of why this is a nice way of doing things.  But yes, considering this didn't catch on no doubt either the docs are poor quality or the thing isn't really something people want.  FWIW I wrote this many years ago, before deriving via.  I just figured you might be interested as it is very similar to your query.<div><br></div><div>The examples could be better.  One thing to note is that you can list a bunch of instances:</div><div><div dir="auto"><div dir="auto"><pre style="white-space:pre-wrap;margin-top:1em;margin-bottom:0px;padding:0.5rem 1rem;background-color:rgb(247,247,247);border:1px solid rgb(221,221,221);border-radius:0.3em;color:rgb(17,17,17);font-size:14px;letter-spacing:0.024px">$($(derive [d|
        instance Deriving (Storable X)
        instance Deriving (Eq X)
        instance Deriving (Show X)
        |]))</pre></div></div><br></div><div>(purely an example, afaik it wouldn't make sense to use TH to generate some canonical Eq and Show instances)</div><div><br></div><div>Whereas with typical `$(mkStorable [t| Storable X|] $)` style you need multiple splices and you need to know the names of these TH functions.<br><br>In retrospect this would probably be better without the `Deriving` wrapper, I think I needed that to disambiguate from the instantiators, which indeed aren't properly documented at all (I don't recall how they work, and don't feel like digging into it much further)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 25, 2022 at 11:21 PM David Feuer <<a href="mailto:david.feuer@gmail.com" rel="noreferrer" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I must admit that looks rather mysterious to me. The documentation I saw doesn't make the benefit of the nested splice terribly obvious.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 25, 2022, 10:53 PM Michael Sloan <<a href="mailto:mgsloan@gmail.com" rel="noreferrer" target="_blank">mgsloan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">You might also be interested in <a href="https://hackage.haskell.org/package/th-utilities-0.2.5.0/docs/TH-Derive.html" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://hackage.haskell.org/package/th-utilities-0.2.5.0/docs/TH-Derive.html</a> - though afaik it didn't catch on.<div dir="auto"><br></div><div dir="auto">The cleverness there is to use nesting splicing, where the inner one generates code involving something like "runDeriver (Proxy @ Storable X) ...", where runDeriver is a method of a typeclass.  The instances of this class implement the code generation that is ultimately used for the output.</div><div dir="auto"><br></div><div dir="auto"><pre style="margin-top:1em;margin-bottom:0px;padding:0.5rem 1rem;background-color:rgb(247,247,247);border:1px solid rgb(221,221,221);border-radius:0.3em;color:rgb(17,17,17);font-size:14px;letter-spacing:0.024px">$($(derive [d|
        instance Deriving (Storable X)
        |]))</pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 22, 2022, 13:48 David Feuer <<a href="mailto:david.feuer@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Okay, I found it: recursion-schemes.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 22, 2022, 3:05 PM David Feuer <<a href="mailto:david.feuer@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">That doesn't work out so well when the class has a bunch of methods. I definitely saw the nice way on Hackage ... somewhere.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 22, 2022, 2:49 PM Brandon Allbery <<a href="mailto:allbery.b@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">allbery.b@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm not aware of anything specifically like that, but the `make…`<br>
functions in <a href="https://hackage.haskell.org/package/deriving-compat-0.6.1/docs/Data-Deriving.html" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://hackage.haskell.org/package/deriving-compat-0.6.1/docs/Data-Deriving.html</a><br>
may allow you to do something similar?<br>
<br>
On Sat, Oct 22, 2022 at 2:32 PM David Feuer <<a href="mailto:david.feuer@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">david.feuer@gmail.com</a>> wrote:<br>
><br>
> I remember seeing a package that offered a function used something like this:<br>
><br>
> $(deriveThingy [d| instance Foo a => Thingy a |])<br>
><br>
> to allow the user to specify the constraint(s) for a generated instance. I'd love to borrow the code for that, but I can't remember what package it was in, what class it derived, etc. Can anyone help?<br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> To (un)subscribe, modify options or view archives go to:<br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
<br>
<br>
<br>
-- <br>
brandon s allbery kf8nh<br>
<a href="mailto:allbery.b@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">allbery.b@gmail.com</a><br>
</blockquote></div>
</blockquote></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>