After breeding for two days, I finally found a solution that compiles without warning and passes my specification test. Below is a compilation excerpt from my code to show what is required. Note, however, that the code is no-op because I did not use parts to perform the permutations:
trait Permutation[P <: Permutation[P]] { this: P => def identity: P def *(that: Int): P def +(that: P): P def unary_- : P final def -(that: P) = this + -that final def unary_+ = this def simplify = this /** Succeeds iff `that` is another permutation with an equivalent sequence. */ /*final*/ override def equals(that: Any): Boolean // = code omitted /** Is consistent with equals. */ /*final*/ override def hashCode: Int // = code omitted // Lots of other stuff: The term string, the permutation sequence, the order etc. } object Permutation { trait Identity[P <: Permutation[P]] extends Permutation[P] { this: P => final override def identity = this
As you can see, the solution is to determine the types and objects of the extractor that are local to the simplifyTop method.
I also included a small example of how to apply such a mix to the Foo class. As you can see, Foo is a little more than a factory for compound permutations of its type. This is a big benefit if you have many classes that are otherwise unrelated.
pompous
However, I can’t help but say that a system like Scala is insanely complicated! I am an experienced Java library developer and very good at Java Generics. However, it took me two days to figure out six lines of code with three definitions of types and objects! If it were not for educational purposes, I would give up this approach.
I am currently tempted by the oracle that Scala will NOT be the next big thing in terms of programming languages because of this complexity. If you are a Java developer who feels a little uncomfortable with Java generics now (and not me), then you will hate a system like Scala because it adds invariants, covariants and contravariants to the concept of Java generics, to say the least.
An all-in-one system, Scala seems to concern more scientists than developers. From a scientific point of view, it's nice to talk about the type of program security. From the point of view of developers, the time taken to clarify these details is wasted because it keeps them from the functional aspects of the program.
Nevermind, I will continue with Scala for sure. The combination of pattern matching, mixing, and high-order features is just too strong to miss. However, I feel that Scala will be a much more productive language without an overly complex type system.
</ & bombastic GT;