# Issue with parameterised derived types

**URL:** <https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340>\
**Category:** Uncategorized\
**Created:** [November 27, 2026, 7:54am UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340 "2026-11-27T07:54:25Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [November 30, 2026, 4:47pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/21 "2026-11-30T16:47:12Z")

</div>

@certik, I guess what I was really asking above is WHY is implementing the LEN PDT so hard and, in hindsight, are there any constraints that could have been imposed on the LEN parameter PDT that could have made its implementation easier and less buggy.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [November 30, 2026, 6:02pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/22 "2026-11-30T18:02:11Z")

</div>

@rwmsu I am implementing it now, here are some tests to start with: [test: add a test suite for len type parameters of PDTs by certik · Pull Request #19461 · lfortran/lfortran · GitHub](https://github.com/lfortran/lfortran/pull/19461) and I’ll see what it takes to pass all tests and error tests. In general nothing is complicated in compilers, as long as you have the right design. If you have a bad design, you will be in a lot of pain later on.

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [November 30, 2026, 6:12pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/23 "2026-11-30T18:12:06Z")

</div>

> [@certik](#):
>
> In general nothing is complicated in compilers, as long as you have the right design.

Thanks, that makes a lot of sense and reinforces what I’ve suspected for a while now. Ie, most of the problems experienced with a lot of the newer Fortran features in some compilers are due to the underlying structure/framework of the compiler being fragile, poorly designed or maybe just poorly implemented and not a problem with the way a feature is defined in the Standard. Even experienced programmers can sometimes program themselves into a box that is very hard to get out of.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [November 30, 2026, 7:19pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/24 "2026-11-30T19:19:34Z")

</div>

> [@certik](#):
>
> If you have a bad design, you will be in a lot of pain later on.

I tried writing a [Fortran interpreter in Fortran](https://github.com/Beliavsky/ffort) using an OpenAI dot, but the design is poor, so it takes a lot more code to cover less of Fortran than ofort, written in C, does, as explained [here](https://github.com/Beliavsky/ffort/blob/main/docs/OFORT-COMPARISON.md) by Opus 5.5, which also said what could be [salvaged](https://github.com/Beliavsky/ffort/blob/main/docs/REWRITE-ROADMAP.md).

> ## **Is this an argument for writing the interpreter in C?**
> 
> …
> 
> ### **Where the language does matter**
> 
> **Points against Fortran:**
> 
> - **No tagged unions or cheap variant types.** This is what slowed ffort’s evaluator: every value is a record with allocatable fields, so values get allocated and copied all the time. In C a value is a small struct with a union and costs almost nothing.
> - **No templates or standard containers yet.** There are no generic hash maps, vectors or trees in the standard library. Fortran 2023’s templates aren’t available in compilers, so each container gets written again for each type.
> - **String handling is clumsy.** Variable-length strings and string building take more code.
> - **Builds are slow and tooling is thinner.** A release build of version 0.49 took about 16 minutes. There are fewer profilers and sanitizers, and compilers are less reliable with heavily nested derived types.
> 
> **Points for Fortran:**
> 
> - **The host compiler does the hard numeric work.** Arrays, intrinsics like `sum` and `matmul`, and kinds and numeric semantics all come built in.
> - **Formatting comes free.** An internal `WRITE` gives exact Fortran output formatting, which C would have to reimplement. That matters for matching gfortran byte for byte.
> - **It is self-hosting.** Contributors who know Fortran can work on it, and extension modules can be ordinary Fortran.
> 
> A rough estimate, not measured: the language accounts for perhaps 1.5–2× in code size and a large factor in speed, the latter mainly through the value representation, which C makes much easier to get right. The remaining several-fold gap in coverage per line comes from the development approach.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [November 30, 2026, 7:24pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/25 "2026-11-30T19:24:19Z")

</div>

> [@certik](#):
>
> In general nothing is complicated in compilers, as long as you have the right design. If you have a bad design, you will be in a lot of pain later on.

I know very little about writing compilers, but I do know that this statement is very true also for application programming. If you have the foresight to start off with the right algorithms and the right data structures, things are much easier both in the present and in the future.

One thing I’ve noticed often is that algorithm choice is more or less a top-down kind of issue, while data structure is more or less a bottom-up kind of issue, so sometimes the best choice is for the two to meet somewhere in the middle levels of the program.

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [November 30, 2026, 7:54pm UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/26 "2026-11-30T19:54:55Z")

</div>

> [@rwmsu](#):
>
> Ie, most of the problems experienced with a lot of the newer Fortran features in some compilers are due to the underlying structure/framework of the compiler being fragile, poorly designed or maybe just poorly implemented

I Agree. There’s also the tight coupling assumptions that were just fine up to a certain standard, but conflict with the new one. Fortran 2008’s submodules is good at providing examples:

gforrtran’s propagation of the `PUBLIC`|`PRIVATE` attribute to the object file level (i.e., `t` versus `T` in `*.obj` and `*.o`) was okay for Fortran 2003, but caused issues with submodules, and it was seemingly too hard to fix properly/quickly.

ifort/fix’s global naming scheme for the `CONTAINed` procedures of a `separate-module-subprogram` breaks if it’s too large, since they never took into account that a submodule symbol might need more than `3x64-1` characters —the currently implemented hack to make it work consists of removing characters from the beginning of the global name and emitting a warning about the name having been truncated.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 1, 2026, 1:43am UTC](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340/27 "2026-12-01T01:43:38Z")

</div>

@rwmsu here is the fairly complete PDT implementation in LFortran that passes all the 77 tests above: [Implement length type parameters of parameterized derived types by certik · Pull Request #19506 · lfortran/lfortran · GitHub](https://github.com/lfortran/lfortran/pull/19506), the ASR-\>LLVM backend is not too bad. But it takes thousands of lines in the frontend, about 2.5k lines in AST-\>ASR, plus 1.5k in two new ASR passes just for len PDT. That seems like a heavy price to pay for a feature that is rarely used. It does include about 900 lines of error checking. I’ll clean it up over the coming days and get it in. So there doesn’t seem to be any blocker or hard problem to solve.

[Previous page](https://fortran-lang.discourse.group/t/issue-with-parameterised-derived-types/11340.md?page=1)
