Fortran-FOSS-Programmers / Fortran-FOSS-Programmers/FIAT

Concatenation of ordered types

Open
#4 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Fortran
Stars
36
Forks
10
PR merge metrics
No merged PRs in 30d

Description

I'd originally intended to overload the concatenation operator for ordered data types. This was to be done by creating a deffered type-bound procedure in the abstract `ordered` type, like below:

``` fortran
type, extends(countable), abstract, public :: ordered
contains
! ...
procedure(concat_func), private, deferred :: concat
generic :: operator(//) => concat
end type ordered

abstract interface
function concat_func(lhs, rhs)
import ordered
class(ordered), intent(in) :: lhs, rhs
class(ordered), allocatable :: concat_func
end function concat_func
end interface
```

One consequence is that this means that the returned, concatenated, object must be an allocatable abstract type. In some cases that can be useful, but in others it's a pain because it would require type-guards to assign it to a variable of the actual type.

Another problem is the question of the ordering of the concatenation. My preference would be to order it such that using the `pop()` method to iterate through the returned object would function as though `pop()` had been used to iterate through the `lhs` object and then to iterate through the `rhs` object. However, doing this requires knowledge of the internal structure of the derived type, which is not available if the interface makes the object `class(ordered)`. Furthermore, the concatenation can be performed much more efficiently if you act on the internal structure of the derived type directly, rather than just accessing it through the (rather few) methods available for `class(ordered)` objects.

One possibility would be to remove the method definition from `ordered` and place separate definitions
in each concrete derived type. This, of course, would mean that it can't be used in a polymorphic manner. Another possibility would be to keep the definition in the `ordered` type and use type-guards in each implementation. This would potentially be quite time consuming.

Thoughts?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.