title: Memoise a function taking a function as argument
body: <p>I want to do some memoization using the <code>R</code> package <code>memoise</code> on the following function taking as argument a function:</p>
  
  <pre><code>library(memoise)
  
  func      = function(x) x
  slowFunc  = function(a,f,b=2) {Sys.sleep(1); a+b}
  quickFunc = memoise(slowFunc)
  
  &gt; system.time(slowFunc(2, func, 3))
     user  system elapsed 
        0       0       1 
  &gt; system.time(slowFunc(2, func, 3))
     user  system elapsed 
     0.00    0.00    0.99 
  </code></pre>
  
  <p>There are two successive calls and the second returns 1 sec on the timing whereas I could have expected something instantaneous.</p>
  
  <p>It is weird but it seems <code>memoise</code> do not apply when arguments are functions ... how the function is represented in the memory to have this working?</p>