
8 Jan
2011
8 Jan
'11
12:42 p.m.
On Sat, 8 Jan 2011, Conor McBride wrote:
Of course, there is an alternative generalisation.
[] and Maybe are both Foldable, hence so is their composition.
There's got to be a thing of type
collapse :: (Foldable f, Alternative a) => f x -> a x
which would do the job.
Nice! It would be collapse = Data.Foldable.foldr (\a b -> pure a <|> b) empty and with transformers:Data.Functor.Compose (or the one from TypeCompose) we get catMaybes = collapse . Compose
Of course, anything which is both foldable and alternative certainly has a function with the type of join.
join = collapse . Compose :-)