I've been watching rust with interest since 0.1, but finally installed the compiler yesterday and started looking through the standard libraries.

I noted that Option has a procedure for it, called chain, which is a specialised version of monadic bind. Being a Haskeller, my immidiate thought was to try to write a trait for this:

        trait Monad<T> {
                fn chain<U>(self, f: &fn(t: T) -> Self<U>) -> Self<U>;
        }

But apparently Self cannot be parameterised.

Is there a way to write traits that model stuff like this?

I then found that when writing the impl for a trait, I seem to be required to write type signatures for the arguments and return type of the method I'm implementing, even though such a type signature (a) already exists in the definition of the trait and (b) should be inferrable anyway. Is this a general limitation of the type checker when it comes to traits?

--
Stephen Paul Weber, @singpolyma
See <http://singpolyma.net> for how I prefer to be contacted
edition right joseph

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to