# Partial inline recursive function (Fibonacci optimization)

**URL:** https://community.haxe.org/t/partial-inline-recursive-function-fibonacci-optimization/1255
**Category:** Haxe
**Created:** [November 8, 2018, 10:03am UTC](https://community.haxe.org/t/partial-inline-recursive-function-fibonacci-optimization/1255 "2018-11-08T10:03:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![AdrianV](https://community.haxe.org/user_avatar/community.haxe.org/adrianv/32/152_2.png) [@AdrianV](https://community.haxe.org/u/AdrianV)
#### Post date: [November 8, 2018, 10:03am UTC](https://community.haxe.org/t/partial-inline-recursive-function-fibonacci-optimization/1255/1 "2018-11-08T10:03:05Z")

</div>

now that we have inline at the call site I wonder if it would be possible to partial inline recursive functions, which would be nice to bring Haxe in front of any language in the unavoidable Fibonacci benchmark.

```haxe
    @:pure
    static function fib(n: Int): Int {
        return n > 1 ? inline fib(n - 1) + fib(n - 2) : n;
    }

```

could be converted and optimized to:

```haxe
    @:pure
    static function fib(n: Int): Int {
        //return n > 1 ? (n > 2 ? fib(n - 2) + fib(n - 3): n - 1) + fib(n - 2) : n;
        return n > 2 ? 2 * fib(n - 2) + fib(n - 3) : n > 1 ? n - 1 : n;
    }

```

this would pulverize any other language 🙂 see here: [http://try-haxe.mrcdk.com/#3fe8A](http://try-haxe.mrcdk.com/#3fe8A)
