[Haskell-cafe] instance Alternative (Either [a])

Tony Morris tmorris at tmorris.net
Wed May 21 23:58:35 UTC 2014


http://hackage.haskell.org/package/validation-0.3.4/docs/Data-Validation.html



On Thu, May 22, 2014 at 7:46 AM, John Meacham <john at repetae.net> wrote:

> On Mon, May 19, 2014 at 8:31 AM, Corentin Dupont
> <corentin.dupont at gmail.com> wrote:
> > However the instance in Control.Monad.Trans.Error.Error gets in the
> way...
> > I cannot use this one, it works only with Strings.
> > My use case is that the Either handle in the Right a final value, or
> else in
> > the Left a list of things "left to do" to compute the value.
> > How can I do?
>
> You want to use a newtype to wrap your Either. It sounds like you would
> want
> to do this independently of the String instance because you are not using
> left as shortcutting failure anyway, rather you want to collect together
> the failure actions.
>
> newtype NotDoneYet b a = NotDoneYet (Either [b] a)
>
> instance Applicative (NotDoneYet b) where
>         Left xs <*> Left ys = Left (xs ++ ys)
>         ...
>
>
> --
> John Meacham - http://notanumber.net/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140522/342f532e/attachment.html>


More information about the Haskell-Cafe mailing list