This page is no longer maintained — Please continue to the home page at

Abstract Types & Self Type questions

No replies
Joined: 2009-08-20,
User offline. Last seen 2 years 32 weeks ago.
Hello,   I am playing around with making some numeric types with varying operations, Eg. (possible to add shares but not multiply them) and have reach the limits of my understanding.   Here is one of my attempts:   trait Addition[T] {
    type N <: { def +(other: N) }
    val value: N       protected implicit def value2wrapper(v: N): T       def +(that: T): T = this.value + that.value
}   The compiler complains that N has a cyclic reference, I think it should be valid. It just means that the type should have a + method that takes a parameter with the same type ...   Another think that I think it may simplify the code would be to be able to use Self as a type:   trait Addition {
    type N <: { def +(other: N) }
    val value: N       protected implicit def value2wrapper(v: N): Self       def +(that: Self): Self = this.value + that.value
}   Is there any way to achieve something in that spirit? in that way it will be possible to do some mixins without type parameters reducing the noise :   class MyNumber extends Number with Addition   instead of   class MyNumber extends Number with Addition[MyNumber]   is just and small difference but it will read more nicely.   regards,   Oscar    


Please consider the environment before printing this email or its attachments.

The contents of this email are for the named addressees only. It contains information which may be confidential and privileged. If you are not the intended recipient, please notify the sender immediately, destroy this email and any attachments and do not otherwise disclose or use them. Email transmission is not a secure method of communication and Man Investments cannot accept responsibility for the completeness or accuracy of this email or any attachments. Whilst Man Investments makes every effort to keep its network free from viruses, it does not accept responsibility for any computer virus which might be transferred by way of this email or any attachments. This email does not constitute a request, offer, recommendation or solicitation of any kind to buy, subscribe, sell or redeem any investment instruments or to perform other such transactions of any kind. Man Investments reserves the right to monitor, record and retain all electronic communications through its network to ensure the integrity of its systems, for record keeping and regulatory purposes.

Visit us at:




Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland