<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 19, 2013 at 9:48 PM,  <span dir="ltr">&lt;<a href="mailto:jabolopes@google.com" target="_blank">jabolopes@google.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br></blockquote><div><br></div><div>Hello!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What is the proper way to implement a non-monadic function that checks<br>
whether a given value is correct and gives a proper error message<br>
otherwise ? What is the recommended option ?<br></blockquote><div><br></div><div>I am not sure, what do you mean by non-monadic. Both (Either String) and Maybe are monads.<br><br></div><div>You can pick up whatever option you like, depending on which option, in your opinion, suits you better for your specific case.<br>
</div><div>There is also a helpful errors [1] package that provide convenient means of converting between the results of the two approaches.<br><br></div><div>Control.Error.Util.hush :: Either a b -&gt; Maybe b<br></div><div>
Control.Error.Util.note :: a -&gt; Maybe b -&gt; Either a b<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
* Either String a<br>
<br>
check val<br>
  | valid val = Right val<br>
  | otherwise = Left errorMsg<br>
<br>
<br>
* Maybe String<br>
<br>
check val<br>
  | valid val = Nothing<br>
  | otherwise = Just errorMsg<br>
<br>
<br>
Cheers,<br>
Jose<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>[1] <a href="http://hackage.haskell.org/package/errors">http://hackage.haskell.org/package/errors</a><br clear="all"><br>-- <br>Sincerely yours,<br>-- Daniil<br>
</div></div>