<div dir="ltr">yeah ... i agreed with Eric,<div>we almost need Lazy and Strict versions of monoid and each blows up in different ways. I definitely had epic space leaks from the lazy Maybe Monoid </div><div><br></div><div>-1 :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 23, 2018 at 11:14 AM, Eric Mertens <span dir="ltr"><<a href="mailto:emertens@gmail.com" target="_blank">emertens@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div>I think changing the strictness of this function could have potentially dramatic performance effects on a wide range of existing code. Exploring existing code to understand the exact impacts would be a huge challenge, and this is a change that would be hard to phase in.<div><br></div><div>The arbitrariness of decisions like this is part of what makes the Monoid class a mess in the first place. Attaching instances like this to otherwise generic types forces us to make arbitrary choices, which are often not documented on the instances themselves.</div><div><br></div><div>While the left-bias behavior might make sense in the case of an instance like we have for First, I don't see why it would be considered more correct in this case.</div><div><br></div><div>I'm -1 on this proposal.</div><div><br></div><div>Best regards,</div><div>Eric Mertens</div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Wed, May 23, 2018 at 4:21 AM Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I feel the the way concerning being lazy as possible and being left-strict where there is a symmetric choice to be made. This seems to be a common theme is base, although I’ve never seen it officially endorsed. I have seen Edward Kmett talk about this on reddit (contrasting it with the Monoid classes in strict-by-default languages), but I cannot find the thread.<br><br><div id="m_8634138045411292430m_-5047299372431800412AppleMailSignature">Sent from my iPhone</div></div><div dir="auto"><div><br>On May 22, 2018, at 7:57 PM, Tikhon Jelvis <<a href="mailto:tikhon@jelv.is" target="_blank">tikhon@jelv.is</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I think the extra laziness makes sense here—it matches the behavior of common functions like &&. My general expectation is that functions are as lazy as they can be and, in the case of operators with two arguments, that evaluation goes left-to-right. (Again like &&.)<div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 22, 2018 at 4:37 PM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think extra laziness here would be a bit surprising.<br>
<div><div class="m_8634138045411292430m_-5047299372431800412h5"><br>
On Tue, May 22, 2018 at 5:57 PM, Donnacha Oisín Kidney<br>
<<a href="mailto:mail@doisinkidney.com" target="_blank">mail@doisinkidney.com</a>> wrote:<br>
> The current semigroup instance for Maybe looks like this:<br>
><br>
> instance Semigroup a => Semigroup (Maybe a) where<br>
> Nothing <> b = b<br>
> a <> Nothing = a<br>
> Just a <> Just b = Just (a <> b)<br>
><br>
> However, it could be lazier:<br>
><br>
> instance Semigroup a => Semigroup (Maybe a) where<br>
> Nothing <> b = b<br>
> Just a <> b = Just (maybe a (a<>) b)<br>
><br>
> This causes different behaviour for Data.Semigroup.First and<br>
> Data.Monoid.First:<br>
><br>
> >>> Data.Monoid.getFirst . foldMap pure $ [1..]<br>
> Just 1<br>
> >>> fmap Data.Semigroup.getFirst . Data.Semigroup.getOption . foldMap<br>
> (pure.pure) $ [1..]<br>
> _|_<br>
><br>
> A different definition for `Option` gets back the old behaviour:<br>
><br>
> newtype LeftOption a = LeftOption { getLeftOption :: Maybe a }<br>
><br>
> instance Semigroup a => Semigroup (LeftOption a) where<br>
> LeftOption Nothing <> ys = ys<br>
> LeftOption (Just x) <> LeftOption ys = LeftOption (Just (maybe x (x<>)<br>
> ys))<br>
><br>
> instance Semigroup a => Monoid (LeftOption a) where<br>
> mempty = LeftOption Nothing<br>
> mappend = (<>)<br>
><br>
> >>> fmap Data.Semigroup.getFirst . getLeftOption . foldMap (LeftOption .<br>
> Just . Data.Semigroup.First) $ [1..]<br>
> Just 1<br>
><br>
> Is there any benefit to the extra strictness? Should this be changed?<br>
><br>
> Another consideration is that the definition could equivalently be<br>
> right-strict, to get the desired behaviour for Last, but I think the<br>
> left-strict definition probably follows the conventions more.<br>
><br>
> I originally posted this to reddit<br>
> (<a href="https://www.reddit.com/r/haskell/comments/8lbzan/semigroup_maybe_too_strict/" rel="noreferrer" target="_blank">https://www.reddit.com/r/<wbr>haskell/comments/8lbzan/<wbr>semigroup_maybe_too_strict/</a>)<br>
> and was encouraged to post it here.<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
><br>
______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>______________________________<wbr>_________________</span><br><span>Libraries mailing list</span><br><span><a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a></span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a></span><br></div></blockquote></div>______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
<br></blockquote></div><br></div>