Skip to content

Instantly share code, notes, and snippets.

@cohama
Last active August 7, 2017 22:18
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 cohama/73a90d99fa036030393727ecd51fcb13 to your computer and use it in GitHub Desktop.
Save cohama/73a90d99fa036030393727ecd51fcb13 to your computer and use it in GitHub Desktop.
fn main() {
repeat_cps(10, "hello", Box::new(|r| {
println!("{:?}", r)
}))
}
fn repeat_cps<'a, A, B>(n: i32, x: A, k: Box<Fn(A) -> B + 'a>) -> B
{
if n == 0 {
k(x)
} else {
repeat_cps(n - 1, x, Box::new(move |z| {
k(z)
}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment