When should I use $ (and can it always be replaced with parentheses)?

前端 未结 5 942
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 21:31

From what I\'m reading, $ is described as \"applies a function to its arguments.\" However, it doesn\'t seem to work quite like (apply ...) in Lisp

5条回答
  •  长发绾君心
    2021-01-04 22:13

    You're mostly understanding it right---that is, about 99% of the use of $ is to help avoid parentheses, and yes, it does appear to be preferred to parentheses in most cases.

    Note, though:

    > :t ($)
    ($) :: (a -> b) -> a -> b
    

    That is, $ is a function; as such, it can be passed to functions, composed with, and anything else you want to do with it. I think I've seen it used by people screwing with combinators before.

提交回复
热议问题