[Haskell-cafe] Error-containing Maybes

Vlatko Basic vlatko.basic at gmail.com
Thu Jun 15 10:25:02 UTC 2017


Something similar to what EitherR does?

https://hackage.haskell.org/package/errors-2.2.0/docs/Data-EitherR.html



-------- Original Message  --------
Subject: [Haskell-cafe] Error-containing Maybes
From: Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>
To: Haskell Cafe <haskell-cafe at haskell.org>
Date: 15/06/17 11:38

> The Maybe type is often (almost always?) used to indicate that a
> computation may fail; specifically, `Maybe a` typically indicates that
> it may not be possible to always produce a value of type `a`.
> 
> However, there are times when the inverse of this is desirable
> (usually within a monadic/side-effectful context): if Nothing is
> returned then the computation was a success; otherwise, an error
> message is returned.  Whilst this usage definitely fits the types, it
> breaks the mould of how we think/use Maybe in most cases and may at
> times cause confusion.  As such, it may be advisable (and I know I've
> done this at least once) to define a `data Result e = Error e |
> Success` data type to model this behaviour.
> 
> Is this a typical enough requirement that would make it worth adding
> such a datatype to base (despite my usual aversion to piling more
> things in there) or having a library up on Hackage just for this very
> simplistic type?
> 
> (Another option would be to use `Either error ()`, which could be
> lifted better into an ExceptT result, albeit with the additional
> useless parameter/value in there.)
> 


More information about the Haskell-Cafe mailing list