<div dir="ltr">Small nitpick, but I would generally put the "exception" or "error" in the Left part of an Either and a correct result in the Right part. <div><br></div><div>This has some advantages. </div><div>1 - Right is right as opposed to wrong. Easy to remember mnemonic.</div><div>2 - It fits neatly with the <font face="monospace, monospace">Monad (Either e)</font> instance.</div><div><br></div><div>Roelof, a nice exercise is to first implement your<font face="monospace, monospace"> f2 </font>function with the <font face="monospace, monospace">Integer -> Maybe Integer</font> type and then with <font face="monospace, monospace">Integer -> Either String Integer</font>.</div><div>If you realize that both <font face="monospace, monospace">Monad Maybe</font> and <font face="monospace, monospace">Monad (Either e)</font> you can use almost the same code.</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-10-31 12:04 GMT+01:00 Darren Grant <span dir="ltr"><<a href="mailto:dedgrant@gmail.com" target="_blank">dedgrant@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I'd expect most Haskellers to recommend something like,</p>
<p dir="ltr"> f2 :: Integer -> Either Integer ErrorString</p>
<p dir="ltr">where ErrorString is some specific error value type. (String may suffice for you.)</p>
<p dir="ltr">This is a safe general solution, but there are many potentially more specific possibilities that might make your program simpler depending on how this function relates to the context it will be used in.</p>
<p dir="ltr">Cheers,<br>
Darren<br>
</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Oct 31, 2015 21:46, "Roelof Wobben" <<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Op 31-10-2015 om 11:40 schreef Darren Grant:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Unfrotunately the answer to this is not simple:<br>
<br>
<a href="http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function</a><br>
<br>
'error' more or less terminates the program in an unreasonable way.<br>
<br>
It would be preferable for f2 to result in a type that can contain the error result to be parsed.<br>
<br>
Cheers,<br>
Darren<br>
<br>
<br>
</blockquote>
<br>
<br>
Oke,<br>
<br>
So I have to change the type of f2.<br>
<br>
To what do I have to change it to make it testable.<br>
<br>
Roelof<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><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>
</blockquote></div>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><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>
<br></blockquote></div><br></div>