On Sun, Mar 06, 2016 at 06:06:40AM -0800, Thomas Wilkinson wrote:
> I am slightly freaked out by the `Lens`es provided by `Pipes.Parse` being
> 'improper'. Could they not be `Getter`s instead?
>
> type Splitter a m = forall x. Getter (Producer a m x) (Producer a m
> (Producer a m x))
> -- Should have " join . view sp == id " for any sp :: Splitter a
> m and p :: Producer a m r
>
> span :: Monad m => (a -> Bool) -> Splitter a m
> splitAt :: Monad m => Int -> Splitter a m
> groupBy :: Monad m => (a -> a -> Bool) -> Splitter a m
> group :: (Monad m, Eq a) => Splitter a m
>
> -- would replace `zoom`
> split :: Splitter a m -> Parser a m r -> Parser a m r
> split sp st = StateT $ \p -> fmap (fmap join) (runStateT st (p^.sp))
In case anyone, like me, was interested in the fully general version of
this here it is:
split :: (Monad m, Functor n)
=> Getting (m (m a)) (m a) (m (m a))
-> StateT (m (m a)) n r -> StateT (m a) n r
split sp st = StateT $ \p -> fmap (fmap join) (runStateT st (p^.sp))
I suspect one could make Parser a newtype and then add a Zoomed instance to
make zoom work with the Getters above, but I haven't checked (not that I am
claiming that is a desirable thing for the pipes-parse API, merely that it
might be possible).
Tom