<Type-bound procedure Example Program>

Module simple_callback
  Type callback_object
    Character(6) :: id = ''
    Logical :: stop = .False.
  Contains
    Procedure :: action => basic_callback_proc
  End Type
Contains
  Subroutine basic_callback_proc(me)
    Class(callback_object) me
    If (me%stop) Then
      If (me%id/='') Then
        Print *,'Goodbye from ',Trim(me%id)
      Else
        Print *,'Goodbye from no-one.'
      End If
    Else If (me%id/='') Then
      Print *,'Hello from ',Trim(me%id)
    End If
    If (me%stop) Stop
  End Subroutine
  Subroutine process(cba)
    Class(callback_object) cba(:)
    Do i=1,Size(cba)
      Call cba(i)%action
    End Do
  End Subroutine
End Module

Program example
  Use simple_callback
  Type(callback_object) x(5)
  x(1) = callback_object('X1',.False.)
  x(3)%id = 'Noone'
  x(5)%id = 'End!'
  x(5)%stop = .True.
  Call process(x)
End Program

■ Execution Results

 Hello from X1
 Hello from Noone
 Goodbye from End!