Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
monad_._haskell [2014/09/11 23:08] nikolaj |
monad_._haskell [2015/01/30 12:51] nikolaj |
||
---|---|---|---|
Line 87: | Line 87: | ||
(<*>) :: m (a -> b) -> m a -> m b | (<*>) :: m (a -> b) -> m a -> m b | ||
(<*>) mg ma = liftM2 id mg my | (<*>) mg ma = liftM2 id mg my | ||
+ | -- or = join $ fmap (\g -> fmap g mx) mg | ||
</code> | </code> | ||
+ | |||
Note that conversely, '<*>' doesn't suffice to define a '>>='. | Note that conversely, '<*>' doesn't suffice to define a '>>='. | ||
- | I'm going to explain what this (<*>) does in mathematical terminology: The Yoneda lemma implies that there is an isomorphism from $FA$ to $\mathrm{nat}(\mathrm{Hom}(A,B),FB)$. Consider a the category with exponential objects and arrows corresponding to components of the natural transformations (such as is the case for Hask, where the above map is $at\mapsto g\mapsto T(g)(ta):FA\to B^A\to FB$), then we can apply the functors arrow map to the latter and obtain a map $FA\to F\,B^A\to FFB)$ to. One could say that this is provides a way to "apply" $tg:F\,B^A$ to $ta:FA$. Note, however, that $T\,B^A$ isn't necessarily a honest function space anymore, so that's abuse of terminology. (For example, 'Noting :: Maybe (Int->Int)' isn't a function. Things still work out, however, because if you pass 'Noting', the outer arrow mapping in the described function takes care of it. In that case the 'tg' value doesn't even matter so this is hardly an "evaluation" of 'Nothing'.). Lastly, if the functor comes with a monadic 'join', then we can get rid of the second $F$ in $FFB$ in the type of the function, and then it's called '<*>'. | + | I'm going to explain what this (<*>) does in mathematical terminology: The Yoneda lemma implies that there is an isomorphism from $FA$ to $\mathrm{nat}(\mathrm{Hom}(A,B),FB)$. Consider a category with exponential objects and arrows corresponding to components of the natural transformations (such as is the case for Hask, where the above map is $at\mapsto g\mapsto T(g)(ta):FA\to B^A\to FB$), then we can apply the functors arrow map to the latter and obtain a map $FA\to F\,B^A\to FFB)$ to. One could say that this is provides a way to "apply" $tg:F\,B^A$ to $ta:FA$. Note, however, that $T\,B^A$ isn't necessarily a honest function space anymore, so that's abuse of terminology. (For example, 'Noting :: Maybe (Int->Int)' isn't a function. Things still work out, however, because if you pass 'Noting', the outer arrow mapping in the described function takes care of it. In that case the 'tg' value doesn't even matter so this is hardly an "evaluation" of 'Nothing'.). Lastly, if the functor comes with a monadic 'join', then we can get rid of the second $F$ in $FFB$ in the type of the function, and then it's called '<*>'. |
== Alternative definitions == | == Alternative definitions == |