I'm going through this source code for learning.
On line 81 I see the following code:
MaybeT . fmap Just $ locked .= False
I was puzzled by the use of the function composition so I loaded it in my repl and replaced it with function application
MaybeT $ fmap Just $ locked .= False
I'm very surprised these two pieces of code give the exact result.
Control.Monad.State.Class.MonadState Game m => MaybeT m ()
In fact, I can understand how function application ($)
is producing this result but I'm floored as to how function composition (.)
is producing this result. The signatures of these two functions are different and I think they should clearly produce different results if one replaces the other.
:t (.) :: (b -> c) -> (a -> b) -> a -> c
:t ($) :: (a -> b) -> a -> b
Can someone explain to me why the ($)
and (.)
are interchangeable in this case.
(a . b) $ c
is the same thing asa $ (b $ c)
- or without the explicit$
, which only is syntactical sugar for grouping:(a . b) c
=a (b c)
– Bergi($)
vs(.)
is a topic we already discussed several times. Just to mention one question: stackoverflow.com/questions/3030675/… – chi