[Haskell-cafe] Help with TH trick

Michael Sloan mgsloan at gmail.com
Wed Oct 26 02:52:59 UTC 2022


You might also be interested in
https://hackage.haskell.org/package/th-utilities-0.2.5.0/docs/TH-Derive.html -
though afaik it didn't catch on.

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.

$($(derive [d|
        instance Deriving (Storable X)
        |]))


On Sat, Oct 22, 2022, 13:48 David Feuer <david.feuer at gmail.com> wrote:

> Okay, I found it: recursion-schemes.
>
> On Sat, Oct 22, 2022, 3:05 PM David Feuer <david.feuer at gmail.com> wrote:
>
>> That doesn't work out so well when the class has a bunch of methods. I
>> definitely saw the nice way on Hackage ... somewhere.
>>
>> On Sat, Oct 22, 2022, 2:49 PM Brandon Allbery <allbery.b at gmail.com>
>> wrote:
>>
>>> I'm not aware of anything specifically like that, but the `makeā€¦`
>>> functions in
>>> https://hackage.haskell.org/package/deriving-compat-0.6.1/docs/Data-Deriving.html
>>> may allow you to do something similar?
>>>
>>> On Sat, Oct 22, 2022 at 2:32 PM David Feuer <david.feuer at gmail.com>
>>> wrote:
>>> >
>>> > I remember seeing a package that offered a function used something
>>> like this:
>>> >
>>> > $(deriveThingy [d| instance Foo a => Thingy a |])
>>> >
>>> > 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?
>>> > _______________________________________________
>>> > Haskell-Cafe mailing list
>>> > To (un)subscribe, modify options or view archives go to:
>>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> > Only members subscribed via the mailman list are allowed to post.
>>>
>>>
>>>
>>> --
>>> brandon s allbery kf8nh
>>> allbery.b at gmail.com
>>>
>> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20221025/8432ec8b/attachment.html>


More information about the Haskell-Cafe mailing list