Re: Request for feedback: deriving strategies syntax

How much of this derivation machinery could NOT be implemented by means of some kind of a (hypothetical) type-backed metaprogramming facility?
I think this would be a wonderful thing to have. Matthew Pickering (cc'd) has expressed a desire to have all the logic for the `bespoke` deriving strategies compartmentalized into a library that could easily be expanded on in the future to support more typeclasses in base. (Bifunctor, anyone?) Unfortunately, each of the major players in today's Haskell metaprogramming scene that I'm aware of have some downfalls that make them unsuitable as `deriving` replacements: * Template Haskell: Not portable. Staging issues make it hard to use as a drop-in replacement for the `deriving` keyword * GHC generics: Can't express all the optimizations that the bespoke `deriving` algorithms perform. Unperformant. * Haskell preprocessors: Difficult to integrate in a typical GHC workflow. Probably wouldn't have all the metadata you'd need to be feature-complete with what `deriving` does today. The way I see it, the whole `deriving` business as it currently stands today is a somewhat-grotesque-but-darn-useful hack that gets around the lack of a truly nice metaprogramming facility in Haskell. I'm holding out hope that the work in https://github.com/shayan-najd/NativeMetaprogramming makes things nicer soon, and then we can revisit this idea. Until then, -XDerivingStrategies provides a way to contain some of the madness of `deriving` after having many features tacked onto it in recent GHC releases. Ryan S.

On Aug 3, 2016, at 8:50 PM, Ryan Scott
wrote: * Template Haskell: Not portable. Staging issues make it hard to use as a drop-in replacement for the `deriving` keyword
I do not understand "not portable" here. Do you mean that some architectures don't support TH? What staging issues? I'm imagining here having `deriving Blah` be surface syntax that desugars into some TH splice. You keep the nice user-facing syntax, but make the deriving mechanism itself specified in TH code. It's an interesting idea, but one probably best tackled after the current proposal. Richard

On Wed, Aug 3, 2016 at 10:52 PM, Richard Eisenberg
I do not understand "not portable" here. Do you mean that some architectures don't support TH?
Sounded to me like they're targeting the standards path, which means not tying it to something that's fairly inherently GHC specific. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I do not understand "not portable" here. Do you mean that some architectures don't support TH?
Template Haskell doesn't play nicely with cross compilation [1] or stage-1 compilers, so Template Haskell is simply a non-starter for a lot of uses. It's why the GHC codebase and boot libraries largely don't use the -XTemplateHaskell extension (aside from the test suite, of course).
What staging issues?
I'm imagining here having `deriving Blah` be surface syntax that desugars into some TH splice. You keep the nice user-facing syntax, but make the deriving mechanism itself specified in TH code.
That won't currently work with the way TH stages its splices. For example, the following code: {-# LANGUAGE PackageImports, TemplateHaskell #-} import "deriving-compat" Data.Eq.Deriving bar :: Bar bar = Bar data Foo = Foo $(deriveEq ''Foo) data Bar = Bar $(deriveEq ''Bar) will fail to compile because of the staging restrictions on Template Haskell splices, whereas replacing the splices with `deriving Eq` would make it compile.
It's an interesting idea, but one probably best tackled after the current proposal.
Completely agreed. :) Ryan S. ----- [1] https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/CrossCompilation

On 2016-08-04 02:50, Ryan Scott wrote:
I'm holding out hope that the work in https://github.com/shayan-najd/NativeMetaprogramming makes things nicer soon, and then we can revisit this idea.
Are there any papers on this? (Or even just blog posts and such.) Sounds really intriguing, but obvious searches didn't find anything. Regards,

I made a ticket to track this issue.
https://ghc.haskell.org/trac/ghc/ticket/12457
Matt
On Thu, Aug 4, 2016 at 6:20 AM, Bardur Arantsson
On 2016-08-04 02:50, Ryan Scott wrote:
I'm holding out hope that the work in https://github.com/shayan-najd/NativeMetaprogramming makes things nicer soon, and then we can revisit this idea.
Are there any papers on this? (Or even just blog posts and such.) Sounds really intriguing, but obvious searches didn't find anything.
Regards,
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (5)
-
Bardur Arantsson
-
Brandon Allbery
-
Matthew Pickering
-
Richard Eisenberg
-
Ryan Scott