<div dir="ltr"><div>> That approach isn't working for you, and it's trying the patience of the cafe. (These are sub-beginner level q's, please use the Beginners' forum....)</div><div><br></div><div>According to <a href="https://www.haskell.org/mailing-lists/">https://www.haskell.org/mailing-lists/</a> , the purpose of haskell-cafe is "General Haskell questions; extended discussions. Forum in which it’s acceptable to ask anything, no matter how naive, and get polite replies."  The OP's questions and efforts are more than appropriate here, and they should expect no less than polite, if not helpful, responses here.<br></div><div><br></div><div>AntC, your replies are not at all polite, and you seem to be misinformed of the purpose of this mailing list.  Please help us maintain a more appropriate environment here in the future, and I would ask the haskell-cafe moderators to assist in this as well.  If you want to direct someone to a different forum, please do so politely and without insulting them.<br></div><div><br></div><div>--Aaron V.<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 5, 2021 at 4:19 PM Anthony Clayden <<a href="mailto:anthony_clayden@clear.net.nz">anthony_clayden@clear.net.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><font face="monospace">> <span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">This whole exercise is my attempt to translate *The </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">Littler MLer* and its last chapter where they go into functors.</span></font><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><font face="monospace"><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">That approach isn't working for you, and it's trying the patience of the cafe. (These are sub-beginner level q's, please use the Beginners' forum. And I'd forgotten that's what you're doing. Your first post in this thread should have said you're talking about ML functors. </span><a href="https://stackoverflow.com/questions/2030863/in-functional-programming-what-is-a-functor#:~:text=In%20the%20ML%20family%20of,programmers%20have%20difficulty%20with%20it" target="_blank">https://stackoverflow.com/questions/2030863/in-functional-programming-what-is-a-functor#:~:text=In%20the%20ML%20family%20of,programmers%20have%20difficulty%20with%20it</a>. says "<span style="color:rgb(36,39,41);font-size:15px">most beginning programmers have difficulty with</span><span style="color:rgb(36,39,41);font-size:15px"> [functors]</span>".)</font></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">I suggest you first go through a Haskell tutorial, and get your knowledge secure of idiomatic Haskell. Even so, I just don't believe you're coming from idiomatic ML. Unless 'The Little MLer' is giving it as obfuscated code, and the objective is to de-obfuscate it.</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">I'd code your `plus2` with pattern-matching:</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> plus2 :: MyNum -> MyNum -> MyNum</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> plus2 MNZero m = m</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> plus2 (OneMoreThan n') m = OneMoreThan $ plus2 n' m</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">Your test for `(x == MNZero)` inside helper function `pCessor` is useless: flow-of-control doesn't take the outer `else` branch unless `x` (i.e. `n`) is _not_ equal `MNZero`.</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">Similar redundant code in the case for `Int`. But that has bigger problems, as Olaf points out: `Int`s can be negative. So if `plus` is called with a negative `n`, it'll call `pCessor` repeatedly until stack overflow (or numeric underflow).</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">AntC</font></span></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>