Created
December 1, 2016 14:19
-
-
Save ethanabrooks/9e423e0c6820eb215a2b959e5e01a697 to your computer and use it in GitHub Desktop.
This file contains 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
use std::ops::Add; | |
#[derive(Debug)] | |
pub enum Expr<'a> { | |
Constant(f32), | |
// ^^^--this is a simplified version. In the real version, | |
// Constant holds large matrices and I would like to | |
// avoid copying it. | |
Add(&'a Node<'a>, &'a Node<'a>), | |
} | |
#[derive(Debug)] | |
pub struct Node<'a> { | |
pub body: Expr<'a> | |
} | |
impl<'a> Add for &'a Node<'a> { | |
type Output = Node<'a>; | |
fn add(self, other: &'a Node<'a>) -> Node<'a> { | |
Node { body: Expr::Add(self, other) } | |
} | |
} | |
fn main() { | |
let a = Node { body: Expr::Constant(1.) }; | |
let f: Node = &(&a + &a) + &a; | |
println!("f: {:#?}", f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment