[GHC] #13403: Derive instances (Applicative, Monad, ...) for structures lifted over functors
GHC
ghc-devs at haskell.org
Thu Mar 9 20:04:39 UTC 2017
#13403: Derive instances (Applicative, Monad, ...) for structures lifted over
functors
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Iceland_jack):
Thanks for taking the time to respond to my proposals
Replying to [comment:2 RyanGlScott]:
> This feels extremely //ad hoc// and not nearly formalized enough to
where I'd be comfortable with it.
At least it gets a reaction :) the proposal was but we can go into the
direction of [https://hackage.haskell.org/package/base-4.9.1.0/docs/GHC-
Generics.html#t:Rep Generic's Rep]
> I have no idea how you could teach GHC to recognize "product types"
It's not just for product types, I should have made myself more clear but
I didn't want to complicate the proposal. This should work for our entire
polynomial arsenal, `Sum`, `Product`, `Identity`, `Const _`, when we get
to weirder things like
[https://hackage.haskell.org/package/bifunctors-5.4.1/docs/Data-Bifunctor-
Biff.html Biff] things start to collide. Maybe it's a matter of picking a
comfortable subset.
> `data Product f g h a = Product (f (g (f a))) (h (f (g a)))`?
That could be encoded as ↓ and we can still derive a whole host of
instances
{{{#!hs
infixr 9 ·
type (·) = Compose
newtype P f g h a = P (Product (f · g · f) (h · f · g) a)
deriving (Functor, Foldable, Traversable, Applicative, Alternative,
Contravariant)
}}}
In any case it could be implemented incrementally.
> What if there are constants like `data Product a = Product Int a`?
They could always be rewritten as (I changed `Int` to `String` to get that
`Applicative` instance)
{{{#!hs
newtype Q a = Q (Product (Const String) Identity a)
deriving (Functor, Foldable, Traversable, Applicative)
}}}
>
> * `newtype Compose f g a = Compose (f (g a))`
> * `data Proxy a = Proxy`
`Compose` and `Proxy` would likely be primitives in what ever subset of
types we support.
Are there other discussions about something similar? Or is this the first
time this is proposed.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13403#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list