<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">Good evening,</p><p style="margin:0px 0px 1.2em!important">Is there a way with TH to generate instances for a class in GHCi? I want to generate instances for a serialization class.</p>
<p style="margin:0px 0px 1.2em!important">I tried to write some TH to do it, but <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">$(foo)</code> in GHCi’s REPL says that it can only be <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Q Exp</code>, not <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Q [Dec]</code>. Sadness.</p>
<p style="margin:0px 0px 1.2em!important">I found <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">qAddTopDecls</code>. I tried to add the class declarations via <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">$(foo >>= qAddTopDecls; stringE "OK!")</code> and it says “Only function, value, and foreign import declarations may be added with <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">addTopDecl</code>". Woe.</p><p style="margin:0px 0px 1.2em!important">I could create a file and then load in that file, but loading modules loses all GHCi's state, which would defeat the purpose of using a REPL in the first place.</p>
<p style="margin:0px 0px 1.2em!important">Any hope?</p>
<p style="margin:0px 0px 1.2em!important">Ciao!</p>
<div title="MDH:SXMgdGhlcmUgYSB3YXkgd2l0aCBUSCB0byBnZW5lcmF0ZSBpbnN0YW5jZXMgZm9yIGEgY2xhc3Mg
aW4gR0hDaT88YnI+PGJyPkkgd2FudCB0byBnZW5lcmF0ZSBpbnN0YW5jZXMgZm9yIGEgc2VyaWFs
aXphdGlvbiBjbGFzcy48YnI+PGJyPkkgdHJpZWQgdG8gd3JpdGUgc29tZSBUSCB0byBkbyBpdCwg
YnV0IGAkKGZvbylgIGluIEdIQ2kncyBSRVBMIHNheXMgdGhhdCBpdCBjYW4gb25seSBiZSBgUSBF
eHBgLCBub3QgYFEgW0RlY11gLiBTYWRuZXNzLjxicj48YnI+SSBmb3VuZCBgcUFkZFRvcERlY2xz
YC4gSSB0cmllZCB0byBhZGQgdGhlIGNsYXNzIGRlY2xhcmF0aW9ucyB2aWEgYCQoZm9vICZndDsm
Z3Q7PSBxQWRkVG9wRGVjbHM7IHN0cmluZ0UgIk9LISIpYCBhbmQgaXQgc2F5cyDigJxPbmx5IGZ1
bmN0aW9uLCB2YWx1ZSwgYW5kIGZvcmVpZ24gaW1wb3J0IGRlY2xhcmF0aW9ucyBtYXkgYmUgYWRk
ZWQgd2l0aCBgYWRkVG9wRGVjbGAiLiBXb2UuPGJyPjxicj5BbnkgaG9wZT88YnI+PGJyPkNpYW8h" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div>