[Haskell-cafe] Generalizing catMaybes
conor at strictlypositive.org
Sat Jan 8 18:05:48 CET 2011
On 8 Jan 2011, at 15:27, Henning Thielemann wrote:
> On Sat, 8 Jan 2011, Conor McBride wrote:
>> On 8 Jan 2011, at 11:14, Henning Thielemann wrote:
>>> For me, the solutions of Dave Menendez make most sense: Generalize
>>> Maybe to Foldable and List to MonadPlus.
>> What has it to do with monads? There's no bind in sight.
> I see a '>>=' in front of each of his expressions.
That'll teach me to wake up first. Sorry.
If you have some m (f x), and you make an (m x) from each
inner x, then you do need something joiny.
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.
Of course, anything which is both foldable and alternative
certainly has a function with the type of join.
More information about the Haskell-Cafe