
Hi, Could someone please point out what is the difference between using $ and parenthesis in the function composition below. Why does the first expression work whereas the second fails. --- $$ head.head$[[1,2],[3,4]] 1 $$ head.head([[1,2],[3,4]]) <interactive>:122:12: Couldn't match expected type ‘a -> [c]’ with actual type ‘[t0]’ Relevant bindings include --- Thanks, Shishir

Function application has the strongest precedence, thus something like
fun1 . fun2 arg
is equivalent to
fun1 . (fun2 arg)
Now, ($) is the same as function application, but has lowest precedence
(even lower than (.)).
infixr 0 ($)
($) :: (a -> b) -> a -> b
f $ x = f x
Thus,
fun1 . fun2 $ arg
is equivalent to
(fun1 . fun2) $ arg
== (fun1 . fun2) arg { apply ($) }
On 14 May 2015 at 02:42, Shishir Srivastava
Hi,
Could someone please point out what is the difference between using $ and parenthesis in the function composition below. Why does the first expression work whereas the second fails. --- $$ head.head$[[1,2],[3,4]] 1 $$ head.head([[1,2],[3,4]])
<interactive>:122:12: Couldn't match expected type ‘a -> [c]’ with actual type ‘[t0]’ Relevant bindings include --- Thanks, Shishir
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat
participants (2)
-
Shishir Srivastava
-
Sumit Sahrawat, Maths & Computing, IIT (BHU)