module test_error
  implicit none

  type :: array_type
     procedure(get_partial_ptr), pass(this), pointer :: get_partial => null()
   contains
     procedure, pass(this) :: grad_reverse
  end type array_type

  interface
     module function get_partial_ptr(this, upstream_grad) result(output)
       class(array_type), intent(inout) :: this
       type(array_type), intent(in) :: upstream_grad
       type(array_type), pointer :: output
     end function get_partial_ptr
  end interface

contains

  function grad_reverse(this, grad) result(output)
    implicit none
    class(array_type), intent(inout) :: this
    type(array_type), intent(in) :: grad
    type(array_type) :: output

    type(array_type), pointer :: ptr

    ! Example implementation of getting the partial derivative
    ptr => this%get_partial(grad)

    output = ptr

  end function grad_reverse


end module test_error

program test
  use test_error
  implicit none


  type(array_type) :: a, b, c

  ! Example usage
  c = a%grad_reverse(b)

contains

end program test