Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'join' for Applicatives?

Tags:

haskell

I'm looking for the following function:

Applicative f => f (f a) -> f a

Hoogle shows me join:

>:t join
join :: Monad m => m (m a) -> m a

Is there a function that matches my desired signature?

like image 265
Kevin Meredith Avatar asked Sep 10 '25 02:09

Kevin Meredith


2 Answers

To expand a bit on Carl's answer, If there was such a thing as join, but for applicatives:

class Applicative f => ApplicativeWithJoin f where
    join' :: f (f a) -> f a

Then you would automatically have a monad:

instance ApplicativeWithJoin m => Monad m where
    return = pure
    x >>= f = join' (f <$> x)
like image 88
SingleNegationElimination Avatar answered Sep 12 '25 23:09

SingleNegationElimination


There is no such function. join is explicitly what Applicative lacks and Monad has.

like image 23
Carl Avatar answered Sep 13 '25 01:09

Carl