Fwd: Reducing boilerplate

Hi devs,
I would like to add the support for the following automatic
instance-deriving extension:
module M where
class G a where
doG :: a -> Int
class P a where
doP :: a -> Int
doP _ = 10
deriving instance G a where -- automatically derived instance
doG = doP
data X = X
instance P X -- derive G X automatically
print (doG X) -- print 10
See the forwarded mail below for the real context. This extension has
been proposed by someone before as InstanceTemplates:
https://ghc.haskell.org/trac/ghc/wiki/InstanceTemplates
I have modified the parser and the renamer accordingly to get:
class M.G a_awb where
M.doG :: a_awb -> Int
class M.P a_ap6 where
M.doP :: a_ap6 -> Int
M.doP _ = 10
instance M.G a_ap6 where
M.doG = M.doP
I am new to the compiler part of GHC, so I have a few questions before
I continue:
1a) does it make sense to store the renamed class instance declaration
in an interface file? (supposing it only uses exported methods/types;
we could check that)
1b) will it be possible to create a new instance declaration in
another module by just doing the substitution [a_ap6 -> X] in it?
(i.e. when we parse "instance P X", do we know that it means [a_ap6 ->
X] in class P (and not [a -> X])?)
2) maybe I should go a different way and store only the derived
instance methods as we store class default methods?
Any insight appreciated!
Thanks,
Sylvain
---------- Forwarded message ----------
From: Sylvain Henry

Sylvain Henry
Hi devs,
I would like to add the support for the following automatic instance-deriving extension:
Hi Sylvain, I suspect the person most qualified to answer these questions will be Simon who is currently in the middle of paper-writing season. Consequently, it may be a while until he is able to answer. That being said, I'm quite happy to hear that someone is thinking about these proposals. Cheers, - Ben

Hi Ben,
Thanks for your answer. No problem, I can wait.
With this proposal, we would have a really nice story about doing FFI
with GHC. I've been playing with DataKinds and other type-related
extensions for a few days (thanks to everyone involved in implementing
them!) and this extension would remove the last glitch:
https://github.com/hsyl20/ViperVM/blob/master/WritingBindings.md
Btw, the Vector part is inspired from what you did here:
https://github.com/expipiplus1/vulkan/pull/1 (thanks!)
Cheers,
Sylvain
2016-03-11 16:51 GMT+01:00 Ben Gamari
Sylvain Henry
writes: Hi devs,
I would like to add the support for the following automatic instance-deriving extension:
Hi Sylvain,
I suspect the person most qualified to answer these questions will be Simon who is currently in the middle of paper-writing season. Consequently, it may be a while until he is able to answer. That being said, I'm quite happy to hear that someone is thinking about these proposals.
Cheers,
- Ben

Great. Is there a clearly-articulated design on a wiki page?
Simon
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of
| Sylvain Henry
| Sent: 11 March 2016 20:59
| To: Ben Gamari

Simon Peyton Jones
Great. Is there a clearly-articulated design on a wiki page?
The design for the relevant GHC extension is here [1]. Cheers, - Ben [1] https://ghc.haskell.org/trac/ghc/wiki/InstanceTemplates
participants (3)
-
Ben Gamari
-
Simon Peyton Jones
-
Sylvain Henry