<p>I would like to add a method to a built-in type (e.g. Double), so that I can use an <code>infix</code> operator. Is that possible?</p>

Yes and no.  Yes, you can make it
seem
like you have added a method to
```
double
```
.  For example:
```
```
class MyRichDouble(d: Double) {
  def <>(other: Double) = d != other
}

implicit def doubleToSyntax(d: Double) = new MyRichDouble(d)
```
```
This code adds the previously-unavailable
```
<>
```
operator to any object of type
```
Double
```
.  So long as the
```
doubleToSyntax
```
method is in scope so that it could be invoked without qualification, the following will work:
```
```
3.1415 <> 2.68     // => true
```
```
The "no" part of the answer comes from the fact that you aren't really adding anything to the
```
Double
```
class.  Instead, you are creating a conversion from
```
Double
```
to a new type which does define the method you want.  This can be a much more powerful technique than the open-classes offered by many dynamic languages.  It also happens to be completely type-safe.  :-)
Some limitations you should be aware of:
This technique does not allow you to
remove
or
redefine
existing methods, just add new ones
The implicit conversion method (in this case,
```
doubleToSyntax
```
) absolutely must be in-scope for the desired extension method to be available
Idiomatically, implicit conversions are either placed within singleton objects and imported (e.g.
```
import Predef._
```
) or within traits and inherited (e.g.
```
class MyStuff extends PredefTrait
```
).
Slight aside: "infix operators" in Scala are actually methods.  There is no magic associated with the
```
<>
```
method which allows it to be infix, the parser simply accepts it that way.  You can also use "regular methods" as infix operators if you like.  For example, the
```
Stream
```
class defines a
```
take
```
method which takes a single
```
Int
```
parameter and returns a new
```
Stream
```
.  This can be used in the following way:
```
```
val str: Stream[Int] = ...
val subStream = str take 5
```
```
The
```
str take 5
```
expression is literally identical to
```
str.take(5)
```
.