応用関数の「join」は?質問する

応用関数の「join」は?質問する

次の機能を探しています:

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

フーグル表示しますjoin:

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

希望する署名に一致する関数はありますか?

ベストアンサー1

もう少し詳しく説明するとカールの答え、 のようなものがjoin、適用可能形以外で存在した場合:

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

すると自動的にモナドが作成されます:

instance ApplicativeWithJoin m => Monad m where
    return = pure
    x >>= f = join' (f <$> x)

おすすめ記事