Open treeowl opened 7 years ago
Oh, and
runAlt :: (Alternative g, Foldable t) => (forall x. f x -> g x) -> ApT f t a -> g a
runAlt f (ApT x) = x f $ getAlt . foldMap Alt
And also (probably?)
instance Alternative g => Alternative (ApT f g) where
empty = ApT $ \_ q -> q empty
ApT x <|> ApT y = ApT $ \p q -> q $
getCompose (x (Compose . pure . p) (Compose . fmap (q . getCompose))) <|>
getCompose (y (Compose . pure . p) (Compose . fmap (q . getCompose)))
And
joinApT :: Monad m => ApT f m a -> m (ApT f Identity a)
joinApT (ApT x) = getCompose $ x (Compose . pure . liftApT) (Compose . (>>= getCompose))
The free
Applicative
transformers aren't exactly well documented, and I have no sense of the efficiency concerns, but this seems to be an obvious Church version:By the way: it would be very nice to document the distinction between
ApF
andApT
.