I want a generic function called "double", which behaves like this and could be applied to any type with `def +(x:T):T` method:

```
double("A")
> "AA"
double(1)
> 2
double(0.2)
> 0.4

```

So I write this function like this:

```
def double[T](x:T):T = { x+x }

```

But when I run it in REPL, scala compains about it:

```
scala> def double[T](x:T):T = { x+x }
<console>:7: error: type mismatch;
 found   : T
 required: String
       def double[T](x:T):T = { x+x }
                                  ^

```

I think [structural type](https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch19s04.html) may be an approach to implement duck typing, and I tried something like this, but it doesn't work either:

```
def double[T <: { def +(x:T):T }](x:T):T = { x + x }
def double[T <: { def +[U<:T](x:U):U}](x:T) = { x + x }

```

Does anyone have ideas about this? Thanks!

---

I found in Haskell, the similar function can be written like this:

```
double x = x + x

```

just wondering why I can't do this in Scala...