The goal is to remove all overhead associated with using Nullable, since we 
know at compile time what path (in the if branch) will result in None vs 
Some.  Since we know this, we can simply inject `function2` into 
`function1`.  However, we have an issue that `function2 ` requires the 
variable `z`.

I found Monad.jl but it is out of date and does not optimize the right way. 
 In fact, it uses so many deeply nested anonymous functions that the 
performance suffers vs other approaches.

I am looking for something that would optimize this:


      function function1(a, b)
        if(a > b)
          c = a + b
          d = a - b
          return (c, d)
        else
          # do anything
          # but return nothing
        end
      end


      function function2(c, d, z)
        return c + d + z
      end


      a = 1
      b = 2
      z = 10


      @mdo Maybe begin
        (c, d) <- Maybe( function1(a, b) )
        res <- function2(c, d, z)
      end


Into this:

      a = 1
      b = 2
      z = 10


      function1(a, b, z)


      function function1(a, b, z)
        if(a > b)
          c = a + b
          return function2(c, d, z)
        else
          # do anything
          # but return nothing
        end
      end


Notice how `function2` was inserted, and also how `function1` has the `z` 
variable added to its parameters.  But again, what is the limit on adding 
variables to the parameters?  And it looks efficient to me, but is it 
really?

This saves us the overhead of using `Nullable{T}`.  And it is an 
optimization we can do at parse time.

**Option 1**: So we could create a function with z already filled in, but 
this would result in the generation of many different functions, for 
different values of z.

**Option 2**: Or we can use Nullable, and safely parse the result, but this 
also introduces unnecessary overhead.

**Option 3**:  Can use macros, but firstly what is the limit on function 
parameters?  Secondly, is there a better way?

I really like the Monad comprehension syntax, its probably the best way to 
describe what we want to do.

Any equivalent of this optimization would be nice, maybe something using 
anon funs, but done correctly.

Reply via email to