[Haskell-beginners] Function Composition

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Wed May 13 21:22:43 UTC 2015


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 <shishir.srivastava at gmail.com>
wrote:

> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150514/563e78cc/attachment.html>


More information about the Beginners mailing list