
On Thu, May 01, 2014 at 01:19:50PM +0200, S D Swierstra wrote:
On 30 Apr 2014, at 15:50 , Edward Kmett
wrote: A few thoughts:
* Splittable has been used as a name historically for splitting random number generators and the like, so the name conflict (especially from somewhere so prominent) would be unfortunate. That can of course be fixed by a simple bikeshedding exercise.
* You should be able to implement this in one pass. e.g. f a -> Either a (f a) rather than as two combinators, but it isn't clear to me what the getNonPure branch can do other than return the original when the scan fails or some partially zonked/expanded version of it.
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
If (Nothing, Nothing) is impossible why not encode it in the type? data OneOrBoth a b = One a | Other b | Both a b class Splittable f where split :: f a -> OneOrBoth (f a) a Tom