在PureScript中,三重小于号(`<<<<<<<`

时间:2015-04-26 18:26:17

标签: purescript

我在a PureScript program中看过这段代码,<<<做了什么?

pinkieLogic :: (Tuple Boolean GameObject) -> GameObject -> GameObject
pinkieLogic (Tuple jumpPressed hater) p =
  hated hater p
  (solidGround
   <<< gravity
   <<< velocity
   <<< jump jumpPressed
   <<< clearSound)

1 个答案:

答案 0 :(得分:9)

<<<right-to-left composition operator。它相当于Haskell中的.。它的工作原理如下:

(f <<< g) x = f (g x)

也就是说,如果你有两个函数 1 并且你把<<<放在那之间,那么你将得到一个新函数,它调用第一个函数,调用结果第二个功能。

因此,该代码可以重写如下:

pinkieLogic :: (Tuple Boolean GameObject) -> GameObject -> GameObject
pinkieLogic (Tuple jumpPressed hater) p =
  hated hater p
  (\x -> solidGround (gravity (velocity (jump jumpPressed (clearSound x)))))

[1]与Haskell的.运算符不同,PureScript also works on categories or semigroupoids中的<<<