Add an extra class to Control.Applicative.Alternative

Edward Kmett ekmett at gmail.com
Thu May 1 18:09:51 UTC 2014


At that point it is very close to but stronger than MonadLogic's msplit:

class MonadPlus<http://hackage.haskell.org/package/base-4.6.0.1/docs/Control-Monad.html#t:MonadPlus>
m
=> MonadLogic m
whereSource<http://hackage.haskell.org/package/logict-0.6.0.2/docs/src/Control-Monad-Logic-Class.html#MonadLogic>

msplit :: m a -> m
(Maybe<http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Maybe.html#t:Maybe>
(a,
m a))

-Edward

On Thu, May 1, 2014 at 2:01 PM, Daniel Gorín <dgorin at dc.uba.ar> wrote:

>
> On 01 May 2014, at 13:19, S D Swierstra <doaitse at swierstra.net> wrote:
>
> > I have probably not been clear enough. The relationship that should hold
> between getPure and getNonPure is as follows:
> >
> > case (getPure p, genNonPure p) of
> >  (Nothing, Nothing)       -> "should not happen since p should have at
> least a pure or a nonpure part"
> >  (Just pp,  Just npp)        -> pure pp <|> npp
> >  (Just np,  Nothing)        -> pure np
> >  (Nothing, Just npp)       -> npp
> >
> > is equivalent to p.
> >
> >
> > I do not see how this would correspond to your use of Either?
> >
> > Doaitse
>
> Would this then be equivalent to the following?
>
> class Alternative f => Splittable f where
>  split :: f a -> (Maybe a, f a)
>
>  isEmpty :: f a -> Bool
>  isEmpty = isNothing . fst . split
>
> One then would have something like:
>
> getPure = fst . split
>
> getNonPure x = guard (not (isEmpty fa)) >> Just fa
>  where fa = snd (split x)
>
> and the expected laws might be easier to state
>
> Daniel
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140501/b00ead58/attachment-0001.html>


More information about the Libraries mailing list