
Hi guys! I'd like to implement the instance in the subject: instance Alternative (Either [a]) 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? Thanks! Corentin

On Mon, May 19, 2014 at 8:31 AM, Corentin Dupont
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/

http://hackage.haskell.org/package/validation-0.3.4/docs/Data-Validation.htm...
On Thu, May 22, 2014 at 7:46 AM, John Meacham
On Mon, May 19, 2014 at 8:31 AM, Corentin Dupont
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, May 22, 2014 at 6:58 AM, Tony Morris
http://hackage.haskell.org/package/validation-0.3.4/docs/Data-Validation.htm...
I don't understand how to use this package. Is it because Either is an ugly name for the data type and Validation is preferable? And AccValidation is to be used over Validation, like in Hungarian notation, to indicate (the possibility of?) a Semigroup instance on Left / Failure? -- Kim-Ee

I use a similar idiom
newtype P b a = P ([b],Maybe a)
Note that the [b] is _outside_ the maybe (or either), this means that
the accumulated value can be propagated through failure.
Notably, <*> and `ap` have very different meanings for this which is
not true for other monads. <*> will collect [b] from both sides while
`ap` will only do the left.
John
John
On Wed, May 21, 2014 at 9:18 PM, Kim-Ee Yeoh
On Thu, May 22, 2014 at 6:58 AM, Tony Morris
wrote: http://hackage.haskell.org/package/validation-0.3.4/docs/Data-Validation.htm...
I don't understand how to use this package.
Is it because Either is an ugly name for the data type and Validation is preferable?
And AccValidation is to be used over Validation, like in Hungarian notation, to indicate (the possibility of?) a Semigroup instance on Left / Failure?
-- Kim-Ee
-- John Meacham - http://notanumber.net/

On 22/05/14 14:28, John Meacham wrote:
Notably, <*> and `ap` have very different meanings for this which is not true for other monads. Please don't do this. Kittens die and all that.
-- Tony Morris http://tmorris.net/

On Thu, May 22, 2014 at 12:21 AM, Tony Morris
On 22/05/14 14:28, John Meacham wrote:
Notably, <*> and `ap` have very different meanings for this which is not true for other monads. Please don't do this. Kittens die and all that.
In my particular case I did this, it is actually collecting a non-deterministic set of values so the difference between the two does not matter for correctness, but is practically useful to have a greater set of errors to choose from. The difference is hidden behind an abstract interface so it actually is externally a monad. Manual imprecise exceptions. I just prefer to think of `ap` as buggy and unrelated to <*> sometimes... John -- John Meacham - http://notanumber.net/

AccValidation has an Applicative instance that accumulates on "Left"
(Failure) as per the previous email. Therefore, it has no Monad.
Validation has a Monad and Applicative the same as Either.
On Thu, May 22, 2014 at 2:18 PM, Kim-Ee Yeoh
On Thu, May 22, 2014 at 6:58 AM, Tony Morris
wrote: http://hackage.haskell.org/package/validation-0.3.4/docs/Data-Validation.htm...
I don't understand how to use this package.
Is it because Either is an ugly name for the data type and Validation is preferable?
And AccValidation is to be used over Validation, like in Hungarian notation, to indicate (the possibility of?) a Semigroup instance on Left / Failure?
-- Kim-Ee

On Thu, May 22, 2014 at 05:10:24PM +1000, Tony Morris wrote:
AccValidation has an Applicative instance that accumulates on "Left" (Failure) as per the previous email. Therefore, it has no Monad.
This applicative is called Errors in the transformers package (in Control.Applicative.Lift, of which it's a special case).

On Thu, May 22, 2014 at 2:10 PM, Tony Morris
AccValidation has an Applicative instance that accumulates on "Left" (Failure) as per the previous email. Therefore, it has no Monad.
Validation has a Monad and Applicative the same as Either.
Thanks for clarifying. So my takeaway is that 1) Validation instead of Either is not so much bikeshedding on the name as aligning with the use-case of AccValidation, and 2) AccValidation vs Either is like the ZippyList applicative vs List monad conflation. -- Kim-Ee
participants (6)
-
Corentin Dupont
-
John Meacham
-
Kim-Ee Yeoh
-
Ross Paterson
-
Tony Morris
-
Tony Morris