How does function application with the $ operator curry in Haskell?

前端 未结 1 1665
面向向阳花
面向向阳花 2021-01-11 23:44

I am learning haskell and am a little confused how the function application operator $ curry\'s.

According to GHC the type of $ is

*Main>:t ($)
(         


        
相关标签:
1条回答
  • 2021-01-12 00:31

    Infix operators have special rules. See this page: http://www.haskell.org/haskellwiki/Section_of_an_infix_operator

    Basically, since $ is an infix operator, ($ 2) actually fixes 2 as the second argument of $, so it is equivalent to flip ($) 2.

    The idea is to make partial application with operators more intuitive, so for example if you map (/ 2) over a list, you can imagine putting each element of the list in the "missing" spot on the left side of the division sign.

    If you want to use your curry_test function this way, you could do

    let x = (`curry_test` "123")
    
    0 讨论(0)
提交回复
热议问题