Last active
December 25, 2015 15:59
-
-
Save tautologico/7002435 to your computer and use it in GitHub Desktop.
monads in rust (1st attempt)
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
| trait Monad<A> { | |
| //fn bind<B>(&self, &fn (b: B) -> Self) -> Self; | |
| fn ret(a: A) -> Self; | |
| } | |
| enum Zoption<T> { | |
| ZSome(T), | |
| ZNone | |
| } | |
| impl<T> Monad<T> for Zoption<T> { | |
| fn ret(a: T) -> Zoption<T> { | |
| ZSome(a) | |
| } | |
| } | |
| fn main() { | |
| let opt = Monad::<int>::ret::<Zoption<int>>(5); // does not compile | |
| match opt { | |
| ZNone => println("This is none"), | |
| ZSome(y) => println!("Some({})", y) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment