Pointwise Monoid with DerivingVia on n-tuples

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

Hi, Am Mittwoch, den 06.02.2019, 15:39 +0200 schrieb Georgi Lyubenov:
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) ```
you probably know that, but this works: newtype Four = Four (Bool, Maybe Int, Bool, Bool) deriving (Semigroup, Monoid) via (Any, Option (First Int), Any, Any) and is operationally equivalent to your data type. You can define a pattern synonym to even the the other syntax. Cheers, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/

This question is answered in section 4.3 of the paper.
https://www.kosmikus.org/DerivingVia/deriving-via-paper.pdf
Cheers,
Matt
On Wed, Feb 6, 2019 at 1:40 PM Georgi Lyubenov
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 _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On 2/6/19 10:33 AM, Matthew Pickering wrote:
This question is answered in section 4.3 of the paper.
Is there a package containing SameRepAs and other such convenient newtypes on Hackage or Github? Cheers, Li-yao
participants (4)
-
Georgi Lyubenov
-
Joachim Breitner
-
Li-yao Xia
-
Matthew Pickering