`twice`

is a higher-order function for applying a given function *f* to an argument twice: it returns a new function which, given an *x*, returns *f(f(x))*:

```
fn main() {
let succ = |x: i32| x + 1;
fn twice<T, F: 'static + Fn(T)->T>(f: F) -> Box<Fn(T)->T> {
Box::new(move |x: T| f(f(x)))};
println!("succ(0) = {}", succ(0));
println!("twice(succ)(0) = {}", twice(succ)(0));
// println!("twice(twice)(succ)(0) = {}", twice(twice)(succ)(0));
}
```

The first two examples work correctly, but the third one, if uncommented, causes a compile error:

```
<anon>:9:48: 9:53 error: the trait `core::ops::Fn<(_,)>` is not implemented for the type `Box<core::ops::Fn(_) -> _>` [E0277]
<anon>:9 println!("twice(twice)(succ)(0) = {}", twice(twice)(succ)(0));
^~~~~
```

Is there a way to redefine `twice`

so it can handle this? Hereâs a link to this same code in the Rust Playground.

Paul McJones