Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active December 25, 2015 15:59
Show Gist options
  • Select an option

  • Save tautologico/7002435 to your computer and use it in GitHub Desktop.

Select an option

Save tautologico/7002435 to your computer and use it in GitHub Desktop.
monads in rust (1st attempt)
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