Another rust exercise

I am trying to implement the monad trait in Rust. Mostly just for fun and for exploring the type system. I’m pretty sure that I won’t be able to fully implement the Monad trait due to the lack of “higher categories”, as explained in this reddit discussion , but I want to see how close I can get. For some reason, I cannot get this code to compile. It seems like it should be. Can someone explain why?

trait Monad<T> { fn lift(val: T) -> Self; } struct Context<T>{ val: T } impl<T> Monad<T> for Context<T> { fn lift(x: T) -> Context<T> { Context{val: x} } } fn main() { let c:Context<int> = Context<int>::lift(5i); } 
+7
source share
1 answer

Static methods defined in the attribute must be invoked through it. So you will have:

 let c: Context<int> = Monad::lift(5); 
+7
source

All Articles