<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">On second thought, my parser's ability to conditionally evaluate to `empty` is also suspicious, maybe a parser can only statically being `empty` or not?<div class=""><br class=""></div><div class="">But technically a parser can evaluate to `empty` or otherwise dynamically, which seems very confusing to me.<br class=""><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2020-10-27, at 17:26, YueCompl via Haskell-Cafe <<a href="mailto:haskell-cafe@haskell.org" class="">haskell-cafe@haskell.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">In [1], Alternative is said being most commonly considered to form a monoid, so that:<div class=""><br class=""><div class=""><br class=""></div><div class="">```hs</div><div class=""><pre style="line-height: 1.3; font-family: monospace, monospace; color: rgb(232, 230, 227); background-color: rgb(27, 30, 31); border: 1px solid rgb(53, 58, 60); padding: 1em; white-space: pre-wrap; overflow-x: hidden; overflow-wrap: break-word; tab-size: 4; font-size: 14px; font-variant-ligatures: normal; orphans: 2; widows: 2;" class=""><span class="c1" style="color: rgb(131, 193, 193); font-style: italic;">-- empty is a neutral element</span>
<span class="nf" style="color: rgb(51, 125, 255);">empty</span> <span class="o" style="color: rgb(168, 160, 149);"><|></span> <span class="n">u</span> <span class="ow" style="color: rgb(176, 49, 255); font-weight: bold;">=</span> <span class="n">u</span>
<span class="nf" style="color: rgb(51, 125, 255);">u</span> <span class="o" style="color: rgb(168, 160, 149);"><|></span> <span class="n">empty</span> <span class="ow" style="color: rgb(176, 49, 255); font-weight: bold;">=</span> <span class="n">u</span>
</pre><div class=""><span class="n">```</span></div><div class=""><span class="n"><br class=""></span></div><div class=""><span class="n">In my particular case wrt Megaparsec, when the artifact parser evaluates to `empty` at eof, I suppose the outer `many` should evaluate to whatsoever previously parsed, but current implementation of Megaparsec makes it conditional:</span></div><div class=""><span class="n"><br class=""></span></div><div class=""><span class="n">*) in case the parser hasn't consumed any input, it works the way as expected</span></div><div class=""><span class="n">*) incase the parser has consumed some input (whitespaces), the outer `many` throws error</span></div><div class=""><span class="n"><br class=""></span></div><div class="">So can I say this is a violation regarding [1]?</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Compl</div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 2020-10-27, at 04:18, Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de" class="">olf@aatal-apotheke.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I used to think that an Alternative is just an Applicative which is<br class="">also a Monoid but apparently there is no consensus about this [1,2]. <br class="">Actually it kind of makes sense to make the 'empty' parser fail:<br class="">Consider the parser combinator<br class=""><br class="">choice = Data.Foldable.asum = foldr (<|>) empty<br class=""><br class="">which folds over a list of Alternatives. Its semantics can be regarded<br class="">analogous to 'any' for a list of Booleans, and in the latter the empty<br class="">list evaluates to False. <br class="">Put differently: The parser (p <|> q) matches at least as many inputs<br class="">than either p or q. Hence the neutral element for <|> ought to be the<br class="">parser that matches the least amount of inputs, but a parser that<br class="">succeeds on the empty string _does_ match some input. It would be the<br class="">neutral element for the monoid operation that concatenates parsers. <br class=""><br class="">Olaf<br class=""><br class="">[1] <a href="https://en.wikibooks.org/wiki/Haskell/Alternative_and_MonadPlus" class="">https://en.wikibooks.org/wiki/Haskell/Alternative_and_MonadPlus</a><br class="">[2] <a href="https://wiki.haskell.org/MonadPlus" class="">https://wiki.haskell.org/MonadPlus</a><br class=""><br class=""><br class=""></div></div></blockquote></div><br class=""></div></div></div>_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.</div></blockquote></div><br class=""></div></div></body></html>