Skip to content

Instantly share code, notes, and snippets.

@rexim
Forked from Minoru/example.ml
Created April 14, 2016 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexim/291cc9420f5a847c34cf5ca4eb496a34 to your computer and use it in GitHub Desktop.
Save rexim/291cc9420f5a847c34cf5ca4eb496a34 to your computer and use it in GitHub Desktop.
OCamlin' along with @rexim
let on f g = fun x y -> f (g x) (g y)
# uncurry from https://thelema.github.io/batteries-included/hdoc/BatPervasives.html
# dunno if you can use that
# line 15 can't be rewritten like that.
# I'm still trying to come up with another solution, but it's really different from the other two
# line 16
List.map (fun (vx, vy) -> atan2 (float_of_int vy) (float_of_int vx))
# ...turns into...
List.map (uncurry (on atan2 float_of_int))
# line 19
List.sort (fun (_, a1) (_, a2) -> compare a1 a2)
# ...turns into...
List.sort (uncurry (on compare snd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment