title: Fortran save procedure as property in derived type
body: <p>Is it possible to store a procedure as a property of a derived type? I was thinking of something along the lines of:</p>
  
  <pre><code>  module funcs_mod
    public :: add
    contains
    function add(y,z) result (x)
      integer,intent(in) :: y,z
      integer :: x
      x = y + z
    end function
    end module
  
    module type_A_mod
    use funcs_mod
    public :: type_A,set_operator
    type type_A
      procedure(),pointer,nopass :: operator
    end type
    contains
    subroutine set_operator(A,operator)
      external :: operator
      type(type_A),intent(inout) :: A
      A%operator =&gt; operator
    end subroutine
    function operate(A,y,z) result(x)
      type(type_A),intent(in) :: A
      integer,intent(in) :: y,z
      integer :: x
      x = A%operator(y,z)
    end function
    end module
  
    program test
    use type_A_mod
    use funcs_mod
    type(type_A) :: A
    call set_operator(A,add)
    write(*,*) operate(A,1,2)
    end program
  </code></pre>
  
  <p>But this doesn't successfully compile. Several errors are displayed including:</p>
  
  <p>1) Syntax error in procedure pointer component</p>
  
  <p>and</p>
  
  <p>2) 'operator' at (1) is not a member of the 'type_a' structure</p>
  
  <p>As well as some unsuccessful use statements. Is there a way to do this correctly? Any help is greatly appreciated.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've modified <code>procedure,pointer</code> to <code>procedure(),pointer</code> and now the errors are</p>
  
  <p>1) FUNCTION attribute conflicts with SUBROUTINE attribute in 'operator'</p>
  
  <p>and </p>
  
  <p>2) Can't convert UNKNOWN to INTEGER(4)</p>
  
  <p>Both refer to the line <code>x = A%operator(y,z)</code></p>