Using the Haskell Function Application Operator ($)

I am reading an article by Bartosh Milevsky in which 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 operator application function in parentheses? I understand that this is usually done in order to use the infix function in the prefix form of the notation, but I do not understand why in this case the function could not simply be expressed as Chan (zipWith $ fs xs) , and wonder what the difference is between these two.

(if you still need context, see the article)

+6
source share
1 answer

In this case, $ is passed to zipWith . This is the same as writing

 zipWith (\ fx -> fx) fs xs 

Without parentheses this would be equivalent

 zipWith (fs xs) 

which is not suitable for type checking.

An operator in parentheses behaves exactly like a regular identifier. The following definition:

 apply = ($) 

the code might look like

 zipWith apply fs xs 
+13
source

Source: https://habr.com/ru/post/980784/


All Articles