<div dir="ltr">There is another possible instance. We can instead write:<div><br></div><div> instance Semigroup a => Semigroup (ZipList a) where</div><div> (<>) = liftA2 (<>)</div><div> instance Monoid a => Monoid (ZipList a) where</div><div> mempty = pure mempty</div><div><br></div><div>This behaves differently, and it is also law-abiding.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 3, 2018 at 5:22 AM, 박신환 <span dir="ltr"><<a href="mailto:ndospark320@naver.com" target="_blank">ndospark320@naver.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:10pt;font-family:NanumGothic,나눔고딕,sans-serif"><p><span>As </span><b><span>instance Alternative ZipList</span></b><span> is defined since <a href="http://4.11.0.0" target="_blank">4.11.0.0</a>:</span><span>
</span></p><pre><a name="m_5069614513993817807_line-125"></a><b><span class="m_5069614513993817807hs-keyword">instance</span><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#Alternative" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-type">Alternative</span></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#ZipList" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-type">ZipList</span></a><span> </span><span class="m_5069614513993817807hs-keyword">where</span><span>
</span><a name="m_5069614513993817807_line-126"></a><span> </span><a name="m_5069614513993817807_local-8214565720323792759"></a><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#empty" target="_blank"><span class="m_5069614513993817807hs-identifier">empty</span></a><span> </span><span class="m_5069614513993817807hs-glyph">=</span><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#ZipList" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">ZipList</span></a><span> </span><span class="m_5069614513993817807hs-special">[</span><span class="m_5069614513993817807hs-special">]</span><span>
</span><a name="m_5069614513993817807_line-127"></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#ZipList" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">ZipList</span></a><span> </span><a name="m_5069614513993817807_local-6989586621679319881"></a><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#local-6989586621679319881" target="_blank"><span class="m_5069614513993817807hs-identifier">xs</span></a><span> </span><a name="m_5069614513993817807_local-8214565720323792760"></a><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#%3C%7C%3E" target="_blank"><span class="m_5069614513993817807hs-operator"><|></span></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#ZipList" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">ZipList</span></a><span> </span><a name="m_5069614513993817807_local-6989586621679319882"></a><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#local-6989586621679319882" target="_blank"><span class="m_5069614513993817807hs-identifier">ys</span></a><span> </span><span class="m_5069614513993817807hs-glyph">=</span><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#ZipList" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">ZipList</span></a><span> </span><span class="m_5069614513993817807hs-special">(</span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#local-6989586621679319881" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">xs</span></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.Base.html#%2B%2B" target="_blank"><span class="m_5069614513993817807hs-operator m_5069614513993817807hs-var">++</span></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/GHC.List.html#drop" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">drop</span></a><span> </span><span class="m_5069614513993817807hs-special">(</span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Data.Foldable.html#length" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">length</span></a><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#local-6989586621679319881" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">xs</span></a><span class="m_5069614513993817807hs-special">)</span><span> </span><a href="http://hackage.haskell.org/package/base-4.11.1.0/docs/src/Control.Applicative.html#local-6989586621679319882" target="_blank"><span class="m_5069614513993817807hs-identifier m_5069614513993817807hs-var">ys</span></a></b><span class="m_5069614513993817807hs-special"><b>)<br></b><br>It seems perfectly fine to make <b>Monoid</b> for <b>ZipList</b> as followings:<br><br><b>instance Semigroup a => Semigroup (ZipList a) where<br> ZipList [] <> ZipList ys = ZipList ys<br> ZipList xs <> ZipList [] = ZipList xs<br> ZipList (x:xs) <> ZipList (y:ys) = ZipList (x <> y : ZipList xs <> ZipList ys)<br><br>instance Semigroup a => Monoid (ZipList a) where<br> mempty = ZipList []</b><br></span><span></span><br>Note that this semantic is similar to that of <b>Maybe</b>.<br></pre></div></div><table style="display:none"><tbody><tr><td><img src="https://mail.naver.com/readReceipt/notify/?img=JdFCbHFTpz%2FYaqgZKrRZM4u%2FKxp4MoiCKoF0Fx2%2FKrivKrJSKqEdKq3SKop0KdIo%2BrkSKAv5W4d5W4C5bX0q%2BzkR74FTWx%2FsWz0Sb4JZ16kqtzCCbrR0Wzm5WXiN.gif" border="0"></td></tr></tbody></table><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><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">-Andrew Thaddeus Martin</div>
</div>