Last active
August 29, 2015 14:24
-
-
Save tiziano88/0c400c9e892ad603faa7 to your computer and use it in GitHub Desktop.
Rust HKT
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
// Option A. | |
trait Functor { | |
fn fmap(self: &Self<A>, Fn(A) -> B) -> Self<B> | |
} | |
// Option B. | |
trait Functor<A,B> { | |
fn fmap(&self, Fn(&A) -> &B) -> ??? | |
} | |
// Option C. | |
trait Functor { | |
type A | |
type B | |
fn fmap(&self, Fn(&Self::A) -> &Self::B) -> ??? | |
} | |
impl Functor for Option<?> { | |
fn fmap(self: &Option<A>, Fn(A) -> B) -> Option<B> { ... } | |
} | |
impl Functor for Iterator<?> { | |
fn fmap(self: &Iterator<A>, Fn(A) -> B) -> Iterator<B> { ... } // Iterator has no generics! | |
} | |
impl Functor for Result<?> { | |
fn fmap(self: &Result<A>, Fn(A) -> B) -> Result<B> { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment