On 4/4/13 9:35 AM, Stephen Paul Weber wrote:
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?

We don't have higher-kinded type parameters. It's a common feature request. I would personally be in favor of taking a patch to add the feature.

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?

In general we require type annotations for functions, both for separate compilation and for code clarity.

Patrick

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

Reply via email to