title: Calling type-bound procedure for an array of derrived types in Fortran
body: <p>Let's assume that I have a derived type <code>Coordinates</code> with its type-bound procedure <code>swap</code>:</p>
  
  <pre><code>module myTypes
      implicit none
      public :: Coordinates  
  
      type Coordinates
          real :: x,y
      contains
          procedure :: swap  ! Error here
      end type
  contains
      subroutine swap(this)
          class (Coordinates) :: this
          this%x = this%x + this%y
          this%y = -(this%y - this%x)
          this%x = this%x - this%y
      end subroutine
  end module
  </code></pre>
  
  <p>Now, if I have an instance of <code>Coordinates</code> called <code>point_A</code>, and if I want to call the type-bound procedure <code>swap</code> for it, I would just write: <code>call point_A%swap</code>. But if I have an array of instances of <code>Coordinates</code>, like:</p>
  
  <pre><code>type(Coordinates), dimension(:), allocatable :: setOfPoints
  </code></pre>
  
  <p>then to call the <code>swap</code> for all the elements of <code>setOfPoints</code>, I would like to write:</p>
  
  <pre><code>call setOfPoints(:)%swap
  </code></pre>
  
  <p>In order to achieve that, I change the code of <code>swap</code> procedure to: </p>
  
  <pre><code>subroutine swap(these)
          class (Coordinates), dimension(:)  :: these
          integer :: i
          do i = 1, size(this)
              this(i)%x = this(i)%x + this(i)%y
              this(i)%y = -(this(i)%y - this(i)%x)
              this(i)%x = this(i)%x - this(i)%y
          end do
  end subroutine
  </code></pre>
  
  <p>Unfortunately, gfortran doesn't like my idea. On the line that I marked in the first piece of code it says:</p>
  
  <pre><code>Error: Passed-object dummy argument of 'swap' must be scalar.
  </code></pre>
  
  <p>Question: how can I call the type-bound procedure for all the instances of the derived type at once? I don't want to put the call in the loop, but I want to do this as I wrote it before, like what we always do with arrays in Fortran.</p>
  
  <p>I read about the <code>ELEMENTAL</code> keyword, but if I want to use it, I need the type-bound procedure to be 'pure', which is not my case. 
  I tried to place a <code>DEFERRED</code> keyword after the word <code>procedure</code>, but then compiler says:</p>
  
  <pre><code>Error: Interface must be specified for DEFERRED binding
  </code></pre>
  
  <p>I created an interface for <code>swap</code>, but I couldn't figure out where to place it. I tried many positions and compiler said that 'interface was unexpected there'.
  Also, I read about <code>SELECT TYPE</code>, but I think it won't help in my case.</p>