Partial application explanation - join

Why is partial use of functions with different signatures performed?

Take Control.Monad.joinas an example:

GHCi> :t (=<<)
(=<<) :: Monad m => (a -> m b) -> m a -> m b
GHCi> :t id
id :: a -> a
GHCi> :t (=<<) id
(=<<) id :: Monad m => m (m b) -> m b

Why does it accept id :: a -> ainstead of argument (a -> m b), since they are clearly different?

+5
source share
3 answers

=<<the type signature says that the first argument is a function from a(nothing) to the monad b.

Well, m bit counts as you please, right? Therefore, we can simply substitute in m bfor each a:

(=<<) :: Monad m => (m b -> m b) -> m (m b) -> m b

idtype says it is a function from something to the same thing. So, if we add in m b(without forgetting the monad restriction), we get:

id :: Monad m => m b -> m b

, .

+10

:

  • a , a t. , a -> b -> c, a -> d -> c a -> b -> Int, b d c Int .
  • , , . , a -> b c -> d (a ~ c, b ~ d).
  • t t', t' t, , t' t. , a -> a a -> b.

, , : "" , , , . , .

+3

a m b , a m b, (=<<) ( a ~ m b) Monad m => (mb -> m b) -> m (m b) -> m b, id, Monad m => m (m b) -> m b.

+2

All Articles