Skip to content

Instantly share code, notes, and snippets.

@ethanabrooks
Created December 1, 2016 14:19
Show Gist options
  • Save ethanabrooks/9e423e0c6820eb215a2b959e5e01a697 to your computer and use it in GitHub Desktop.
Save ethanabrooks/9e423e0c6820eb215a2b959e5e01a697 to your computer and use it in GitHub Desktop.
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