Skip to content

Instantly share code, notes, and snippets.

@dbrattli
Created October 7, 2018 10:42
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 dbrattli/dfabab0a61dd69d0ca44217855e776e3 to your computer and use it in GitHub Desktop.
Save dbrattli/dfabab0a61dd69d0ca44217855e776e3 to your computer and use it in GitHub Desktop.
Pythagoras CPS
let addCps a b cont : unit =
cont (a + b)
let squareCps x cont : unit =
cont (x * x)
let sqrtCps x cont : unit =
cont (sqrt x)
// Pythagoras rewritten in CPS
let pythagorasCps a b cont : unit =
squareCps a (fun aa ->
squareCps b (fun bb ->
addCps aa bb (fun aabb ->
sqrtCps aabb (fun result ->
cont result)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment