【发布时间】:2011-04-12 19:41:00
【问题描述】:
Scala 有类似Haskell's $ 的运算符吗?
-- | Application operator. This operator is redundant, since ordinary
-- application @(f x)@ means the same as @(f '$' x)@. However, '$' has
-- low, right-associative binding precedence, so it sometimes allows
-- parentheses to be omitted; for example:
--
-- > f $ g $ h x = f (g (h x))
--
-- It is also useful in higher-order situations, such as @'map' ('$' 0) xs@,
-- or @'Data.List.zipWith' ('$') fs xs@.
{-# INLINE ($) #-}
($) :: (a -> b) -> a -> b
f $ x = f x
【问题讨论】:
-
为了使问题独立,如果您解释一下 Haskell 构造是/做什么会很好。
-
$ 显然是右结合的,并且优先级较低 learnyouahaskell.com/…。