News for hackers. Stuff that matters.
Re:A few things to remember while coding in Python by pcwalton on Sunday May 20, 2012 @04:07PM (#3999904)
Rust typeclasses solve this problem; you can create a suite of methods with syntax like this:

    impl methods<T> for [T] {
        fn filter(f : fn(T)->bool) -> [T] { ... }
        fn map<U>(f : fn(T)->U) -> [U] { ... }
    }
And then you can call it with syntax like:

    println(#fmt("%?", [ 1, 2, 3 ].map { |x| x + 3 }));
    // prints "[ 4, 5, 6 ]"
The methods are properly scoped, so code that isn't in your module needs to import your methods to use them. That way, you avoid introducing strange action-at-a-distance in your code.

There are no comments on this comment yet.