Yeah, non-monadic is not the best term... The problem is that it's always so hard to communicate when you want to say a total function that is not in the context of the IO monad. There should be a simple, short name for these functions, so we can easily talk about them.
What ends up happening a lot of the times is that people on the mailing list call these "pure" functions, and immediately they get an email saying that Haskell is pure, so everything is a pure function. In the end, it doesn't really help... Jose On Mon, Aug 19, 2013 at 10:09:13PM +0400, Daniel F wrote: > On Mon, Aug 19, 2013 at 9:48 PM, <jabolo...@google.com> wrote: > > > 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 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe