[Haskell-cafe] Pointwise Monoid with DerivingVia on n-tuples
Georgi Lyubenov
godzbanebane at gmail.com
Wed Feb 6 13:39:57 UTC 2019
Hi!
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,
=======
Georgi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190206/cfb3a350/attachment.html>
More information about the Haskell-Cafe
mailing list