[Haskell-cafe] Pointwise Monoid with DerivingVia on n-tuples
matthewtpickering at gmail.com
Wed Feb 6 15:33:34 UTC 2019
This question is answered in section 4.3 of the paper.
On Wed, Feb 6, 2019 at 1:40 PM Georgi Lyubenov <godzbanebane at gmail.com> wrote:
> I would like to use `DerivingVia` to do something like this:
> import Data.Semigroup
> data Four = Four Bool (Maybe Int) Bool Bool
> deriving (Semigroup, Monoid) via (Any, Option (First Int), Any, Any)
> This, however, doesn't work, because `(Any, Option (First Int), Any, Any)` is not coercible to `Four`.
> Even if I do
> data Four a b c d = Four a b c d
> type Concrete = Four Bool (Maybe Int) Bool Bool
> `Concrete` is still not coercible to `(Any, Option (First Int), Any, Any)`.
> This seems like a very common thing you would want to do (for me at least it pops up often, to want to have a `Monoid` instance that is just a pointwise Monoid over it's arguments (exactly the way an n-tuple is a `Monoid`). But I don't seem to be finding an easy way to do this. I am aware of `generic-deriving` but `DerivingVia` seems like it should be able to handle something like this, with only `Coercible` holding it back (?).
> Thanks in advance,
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe