title: run-time polymorphism in fortran 2003
body: <p>I'm writing some code in Fortran 2003 that does a lot of linear algebra with sparse matrices. I'm trying to exploit some of the more abstract features of the new standard so I have simpler programs without too much repeated code.</p>
  
  <p>I have a procedure <code>solver</code> which takes in a matrix, some vectors, the tolerance for the iterative method used etc. I'm passing a pointer to a procedure called <code>matvec</code> to it; <code>matvec</code> is the subroutine we use for matrix-vector multiplications.</p>
  
  <p>The problem is, sometimes <code>matvec</code> is a procedure which takes in extra arguments <code>colorlist, color1, color2</code> above the usual ones sent to this procedure. I can think of several ways of dealing with this.</p>
  
  <p>First idea: define two different abstract interfaces <code>matvec1</code>, <code>matvec2</code> and two different solvers. This works but it means duplicating some code, which is just what I'm trying to avoid.</p>
  
  <p>Another idea: keep the same abstract interface <code>matvec</code>, and make the extra arguments <code>colorlist</code>, <code>color1</code>, <code>color2</code> optional. That means making them optional in every matvec routine -- even ones for which they're not really optional, and for routines where they're not even used at all. Pretty sure I'll go to hell if I do this.</p>
  
  <p>I can think of plenty of other less than optimal solutions. I'd like some input on this -- I'm sure there's some elegant way to do it, I'm just not sure what it is.</p>