
On Mon, Aug 19, 2013 at 9:48 PM,
Hi,
Hello!
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 ?
I am not sure, what do you mean by non-monadic. Both (Either String) and Maybe are monads. You can pick up whatever option you like, depending on which option, in your opinion, suits you better for your specific case. There is also a helpful errors [1] package that provide convenient means of converting between the results of the two approaches. Control.Error.Util.hush :: Either a b -> Maybe b Control.Error.Util.note :: a -> Maybe b -> Either a b
* Either String a
check val | valid val = Right val | otherwise = Left errorMsg
* Maybe String
check val | valid val = Nothing | otherwise = Just errorMsg
Cheers, Jose
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[1] http://hackage.haskell.org/package/errors -- Sincerely yours, -- Daniil