title: Interface mismatch in dummy procedure 'f' when passing a function to a subroutine
body: <p>I am trying to write a subroutine (for minimisation) that has two arguments:</p>
  
  <ul>
  <li>an array <code>x</code> of any length</li>
  <li>a function <code>f</code> that takes an array of that length and returns a scalar</li>
  </ul>
  
  <p>example module:</p>
  
  <pre><code>module foo
  
  contains
  
    subroutine solve(x, f)
      real, dimension(:), intent(inout) :: x
      interface
        real pure function f(y)
          import x
          real, dimension(size(x)), intent(in) :: y
        end function
      end interface
  
      print *, x
      print *, f(x)
    end subroutine
  
  end module
  </code></pre>
  
  <p>and test program:</p>
  
  <pre><code>use foo
  
  real, dimension(2) :: x = [1.0, 2.0]
  
  call solve(x, g)
  
  contains
  
    real pure function g(y)
      real, dimension(2), intent(in) :: y
  
      g = sum(y)
    end function
  
  end
  </code></pre>
  
  <p>gfortran fails on:</p>
  
  <pre><code>call solve(x, g)
                1
  Error: Interface mismatch in dummy procedure 'f' at (1): Shape mismatch in dimension 1 of argument 'y'
  </code></pre>
  
  <p>If I change <code>size(x) =&gt; 2</code> then it compiles (and runs) fine. It also works fine if I change  <code>: =&gt; 2</code>. But neither of these solutions gets me what I want. </p>
  
  <p>Any ideas on how I can achieve this? </p>