half :: Int -> (Int -> Cont r Int) -> Cont r Int
half n next = if n `mod` 2 == 0
then next (n `div` 2)
else return (1)
> runCont (callCC (half 4)) (2 *)
4
> runCont (callCC (half 3)) (2 *)
2
half :: Int -> (Int -> Cont r Int) -> Cont r Int
half n next = if n `mod` 2 == 0
then next (n `div` 2)
else return (1)
double :: Int -> Cont r Int
double = return . (2 *)
> runCont (callCC $ \ e -> half 3 e >>= double) id
1
> runCont (callCC $ \ e -> half 4 e >>= double) id
4
half :: Int -> (Int -> Cont r Int) -> Cont r Int
half n exit = if n `mod` 2 == 0
then return (n `div` 2)
else exit (1)
double :: Int -> Cont r Int
double = return . (2 *)
> runCont (callCC $ \ e -> half 3 e >>= double) id
1
> runCont (callCC $ \ e -> half 4 e >>= double) id
4