As instance Alternative ZipList is defined since 4.11.0.0: instance Alternative ZipList where empty = ZipList [] ZipList xs <|> ZipList ys = ZipList (xs ++ drop (length xs) ys) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
There is another possible instance. We can instead write: instance Semigroup a => Semigroup (ZipList a) where (<>) = liftA2 (<>) instance Monoid a => Monoid (ZipList a) where mempty = pure mempty This behaves differently, and it is also law-abiding. On Thu, May 3, 2018 at 5:22 AM, 박신환 <[hidden email]> wrote:
-Andrew Thaddeus Martin
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
I aim to make the semantic consistent compared to that of other type classes (here Maybe).
Also note that your instance is identical to upcoming Ap, as Ap (ZipList a). I also aim to make Monoids as diverse as possible.
-----Original Message----- There is another possible instance. We can instead write: instance Semigroup a => Semigroup (ZipList a) where (<>) = liftA2 (<>) instance Monoid a => Monoid (ZipList a) where mempty = pure mempty This behaves differently, and it is also law-abiding. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
It is worth noting that Maybe a and [a] are rather special cases. The former is the monoid you get from adjoining a unit to a semigroup. The latter is the free monoid. Most other monoids for things wrapped in an applicative are either based on the Alternative instance which inherently provides a monoidal structure or based on lifting a monoid pointwise into the data type. Here we have at least 3-4 possible, quite reasonable, monoids at play, and no real reason to choose any one of them over the others. In that situation, our general practice thus far has been to resist choosing if a choice hasn't already been made, simply because there is no real manner other than memorization / code inspection for a user to know which instance we happened to pick. I'm -1 on adding the instance proposed here. Sent from my iPhone
_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
I'm not refering that Maybe makes Monoid by adding the identity element. I'm refering that the Monoid (Maybe (First a)) have the same semantic as Alternative Maybe.
So I'm suggesting that the same semantic should go to Monoid (ZipList (First a)) for Alternative ZipList.
-----Original Message----- It is worth noting that Maybe a and [a] are rather special cases. The former is the monoid you get from adjoining a unit to a semigroup. The latter is the free monoid. Most other monoids for things wrapped in an applicative are either based on the Alternative instance which inherently provides a monoidal structure or based on lifting a monoid pointwise into the data type. Here we have at least 3-4 possible, quite reasonable, monoids at play, and no real reason to choose any one of them over the others. In that situation, our general practice thus far has been to resist choosing if a choice hasn't already been made, simply because there is no real manner other than memorization / code inspection for a user to know which instance we happened to pick. I'm -1 on adding the instance proposed here. Sent from my iPhone _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries |
Free forum by Nabble | Edit this page |