Add an extra class to Control.Applicative.Alternative

Daniel Gorín dgorin at dc.uba.ar
Thu May 1 18:01:54 UTC 2014


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




More information about the Libraries mailing list