<div>Dear Cafe,</div><br><div>Regarding the Alternative instance of ParsecT from Megaparsec here: <a href="https://link.getmailspring.com/link/34AABC73-FAC8-4126-8356-62E7FE0DA273@getmailspring.com/0?redirect=https%3A%2F%2Fgithub.com%2Fmrkkrp%2Fmegaparsec%2Fblob%2Fccf314b0b940bdbfec3820b18f42d241e6920b61%2FText%2FMegaparsec%2FInternal.hs%23L202-L205&recipient=aGFza2VsbC1jYWZlQGhhc2tlbGwub3Jn" title="https://github.com/mrkkrp/megaparsec/blob/ccf314b0b940bdbfec3820b18f42d241e6920b61/Text/Megaparsec/Internal.hs#L202-L205">https://github.com/mrkkrp/megaparsec/blob/ccf314b0b940bdbfec3820b18f42d241e6920b61/Text/Megaparsec/Internal.hs#L202-L205</a></div><code><pre style="background-color:rgba(0,0,0,0.05);padding:0.2em 1em"><div><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(126, 107, 95)">-- | 'empty' is a parser that __fails__ without consuming input.</span></font></span></div><div><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(204, 82, 75)">instance</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">(</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(107, 149, 197)">Ord</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(130, 174, 216)">e</span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">,</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(107, 149, 197)">Stream</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(130, 174, 216)">s</span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">)</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(204, 82, 75)">=></span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(107, 149, 197)">Alternative</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">(</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(107, 149, 197)">ParsecT</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(130, 174, 216)">e</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(130, 174, 216)">s</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(130, 174, 216)">m</span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">)</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(204, 82, 75)">where</span></font></span></div><div><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)">empty </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(204, 82, 75)">=</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> mzero</span></font></span></div><div><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">(</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(102, 168, 157)"><|></span></font></span><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 190, 152)">)</span></font><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> </span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(204, 82, 75)">=</span></font></span><span style="color:rgb(212, 190, 152)"><font style="font-family:"Droid Sans Mono", monospace, monospace, "Droid Sans Fallback""><span style="color:rgb(212, 191, 160)"> mplus</span></font></span></div></pre></code><div>I come to this question, does it violate the laws of Alternative/Monoid to implement  empty/mempty with mzero from MonadPlus?</div><br><div>First of all, can I somehow regard Alternative as a repurposed Monoid? So this question applies similarly to Monoid as well?</div><br><div>Then I think the lack of failure semantic in Alternative/Monoid might have two different interpretations:</div><br><div>1) It must NOT fail</div><div>2) Whether it can fail or not is not cared</div><br><div>Which one is correct? I feel 1) is in spirit of purism, that pure code should not fail, but it's a monad, then 2) may in monad's spirit to be effectful and composable with other effects including failing.</div><br><div>I'd think it violates the law when interpretation 1) is taken.</div><br><div>Background about my confusion: <a href="https://link.getmailspring.com/link/34AABC73-FAC8-4126-8356-62E7FE0DA273@getmailspring.com/1?redirect=https%3A%2F%2Fgithub.com%2Fmrkkrp%2Fmegaparsec%2Fissues%2F429%23issuecomment-716170935&recipient=aGFza2VsbC1jYWZlQGhhc2tlbGwub3Jn" title="https://github.com/mrkkrp/megaparsec/issues/429#issuecomment-716170935">https://github.com/mrkkrp/megaparsec/issues/429#issuecomment-716170935</a><br></div><div>The parsing of whitespaces is so handled in Megaparsec's idiom that every lexeme should consume (discard) all whitespaces following it. But after tinkered around with some related issues, I by now would think a silent, joinable <code>empty</code> / <code>mempty</code>  might be more sense making for each whitespace block to be parsed individually, i.e. without association with any lexeme while neither will fail the overall parsing. </div><br><div>The demand comes in that I'd like the doc comment parser to evaulate to <code>empty</code>  and contribute nothing to an enclosing <code>many</code>  , in case all following it is whtespaces till eof; while in case it's followed by some artifact definition, the doc comment parser should evaluate to a syntactic doc node  assoicated with that artifact. <code>empty</code>  seems an ideal device for that purpose, but in the fact it is implemented with <code>mzero,</code> the overall parsing will fail, which makes it infeasible.</div><br><div>Best regards,</div><div>Compl</div><br><img class="mailspring-open" alt="Sent from Mailspring" width="0" height="0" style="border:0; width:0; height:0;" src="https://link.getmailspring.com/open/34AABC73-FAC8-4126-8356-62E7FE0DA273@getmailspring.com?me=1684b01a&recipient=aGFza2VsbC1jYWZlQGhhc2tlbGwub3Jn">