[ create a new paste ] login | about

Link: http://codepad.org/SIK67HUN    [ raw code | output | fork ]

azumih - Haskell, pasted on Apr 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- continuation passing
add'cps :: Int -> Int -> (Int -> r) -> r
add'cps x y k = k $ x + y

square'cps :: Int -> (Int -> r) -> r
square'cps x k = k $ x * x

pythagoras'cps :: Int -> Int -> (Int -> r) -> r
pythagoras'cps x y k =
 square'cps x $ \x'squared ->
 square'cps y $ \y'squared ->
 add'cps x'squared y'squared $ \sum'of'squares ->
 k sum'of'squares

main = pythagoras'cps 2 3 print


Output:
1
13


Create a new paste based on this one


Comments: