I'm reading a piece by Bartosz Milewski wherein he defines the following function:
instance Applicative Chan where
pure x = Chan (repeat x)
(Chan fs) <*> (Chan xs) = Chan (zipWith ($) fs xs)
Why is the function application operator in parenthesis? I understand this is normally done in order to use an infix function in prefix notation form, but I don't understand why, in this case, the function couldn't couldn't simply be expressed as Chan (zipWith $ fs xs)
, and wonder what the difference between the two is.
(if you still need context, refer to the article)
In this case, $
is being passed in to zipWith
. It's the same as writing
zipWith (\ f x -> f x) fs xs
Without parentheses, it would have been equivalent to
zipWith (fs xs)
which is not going to typecheck.
An operator in parentheses behaves exactly like a normal identifier. With the following definition:
apply = ($)
the code could have looked like
zipWith apply fs xs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With