On Mon, Aug 19, 2013 at 1:48 PM, <jabolo...@google.com> wrote:

> What is the proper way to implement a non-monadic function that checks
> whether a given value is correct and gives a proper error message
> otherwise ? What is the recommended option ?
>
> * Either String a
>

Preferred, usually, since Nothing is regarded as an error condition of
sorts: the Monad instance for Maybe associates Nothing with `fail`, which
is invoked on failed pattern matches; likewise it's mzero for MonadPlus and
mempty for Monoid, both of which use it (differently) to reflect certain
"failure" scenarios).

If nothing else, it would be highly confusing to see Nothing associated
with success given its widespread association with failure.

Alternatively, have you considered using your own ADT? `data Validity =
Success | Failure String` would give you more readable / comprehensible
code without needing to worry about assumptions or common usage.

-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to