Skip to content

Instantly share code, notes, and snippets.

@AKST
Forked from anonymous/playground.rs
Created May 24, 2015 13:05
Show Gist options
  • Save AKST/e03a4c0a1b5d0cf8951e to your computer and use it in GitHub Desktop.
Save AKST/e03a4c0a1b5d0cf8951e to your computer and use it in GitHub Desktop.
enum Thunk<'a> {
Instant(Atom<'a>),
Defered(&'a fn() -> Atom<'a>)
}
enum Atom<'a> {
Error,
Ni32(i32),
Function(&'a fn(Thunk<'a>) -> Atom<'a>)
}
type Return<'a> = Fn(Thunk<'a>) -> ();
type Yield<'a> = Fn(Atom<'a>) -> ();
impl<'a> Thunk<'a> {
fn await(self, callback: &Yield<'a>) {
match self {
Thunk::Instant(atom) => callback(atom),
Thunk::Defered(func) => callback(func())
}
}
}
fn plus<'a>(a: Thunk<'a>, b: Thunk<'a>, cb: &Return<'a>) {
// a.await(&|ay| {
// b.await(&|by| {
// })
// })
// a.await(&|aYield| b.await(&|bYield|
// cb(Thunk::Instant(match (aYield, bYield) {
// (Atom::Ni32(aNum), Atom::Ni32(bNum)) => Atom::Ni32(aNum + bNum),
// _ => Atom::Error
// }))
// ));
}
fn main() {
// let two = Thunk::Instant(Atom::Ni32(2));
// let four = plus(two, two, &|result| {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment