Created
          May 24, 2015 13:05 
        
      - 
      
 - 
        
Save anonymous/3fb7f81b05b3c7e688a3 to your computer and use it in GitHub Desktop.  
    Shared via Rust Playground
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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