Created
April 21, 2016 06:48
-
-
Save charlesetc/32a5c5be1f1edf1d9d2ca644c50a86cf to your computer and use it in GitHub Desktop.
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
#[macro_export] | |
macro_rules! then { | |
($op1:expr => $op2:expr) => { | |
Monad::bind($op1, Box::new(move |_| { | |
$op2 | |
})) | |
} | |
} | |
// Kind of like `do` notation in haskell. | |
#[macro_export] | |
macro_rules! perform { | |
($e:expr ; $($rest:tt)+) => ({{ | |
then!($e => perform!($($rest)*)); | |
}}); | |
($b:expr => $a:ident ; $($rest:tt)*) => ({ | |
Monad::bind($b, Box::new(move |$a| { | |
perform!($($rest)*) | |
})) | |
}); | |
($e:expr ; ) => { $e; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment