Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the triple less-than sign (`<<<`) do in PureScript?

Tags:

purescript

I've seen this code in a PureScript program, what does <<< do?

pinkieLogic :: (Tuple Boolean GameObject) -> GameObject -> GameObject
pinkieLogic (Tuple jumpPressed hater) p =
  hated hater p
  (solidGround
   <<< gravity
   <<< velocity
   <<< jump jumpPressed
   <<< clearSound)
like image 578
Andrea Avatar asked Apr 26 '15 18:04

Andrea


1 Answers

<<< is the right-to-left composition operator. It's equivalent to . in Haskell. It works like this:

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

That is, if you have two functions1 and you put <<< between then, you'll get a new function that calls the first function with the result of calling the second function.

So, that code could be rewritten as follows:

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

[1] Unlike Haskell's . operator, <<< in PureScript also works on categories or semigroupoids.

like image 151
Andrea Avatar answered Nov 09 '22 06:11

Andrea