Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why has the chosen system resulted in requiring manual instantiation? #107

Open
dacarnazzola opened this issue Aug 25, 2023 · 2 comments
Open

Comments

@dacarnazzola
Copy link

This seems like a consequence of choosing to parameterize entire modules (and permitting nesting of templates) rather than the approaches taken by other modern languages (see the comparison to Go, Rust, Haskell).

What was the driving motivation behind such a system design? I find the manual instantiation of templates absolutely terrible for users of the language, and showing a seeming disregard for those that came before. Go, Rust, and Swift all have generic systems with "strong concepts," based around common interfaces and composition. Yet, the proposal for Fortran looks most similar to C++ templates, the only system brought up as a bad example (specifically due to "no concepts," followed by "concepts light").

This has been a large group effort by many experienced, well educated, and well meaning people - so I am confused what logic lead us to the current point.

@ivan-pi
Copy link

ivan-pi commented Jan 22, 2024

What was the driving motivation behind such a system design? I find the manual instantiation of templates absolutely terrible for users of the language, and showing a seeming disregard for those that came before.

I haven't been involved in this effort, but I believe the motivation was to prevent the long error messages that can result from template instantiation. Instead the (in)validity of template is supposed to be easily detectable, so that an understandable error message can be given.

@ivan-pi
Copy link

ivan-pi commented Jan 22, 2024

What was the driving motivation behind such a system design? I find the manual instantiation of templates absolutely terrible for users of the language, and showing a seeming disregard for those that came before.

I haven't been involved in this effort, but I believe the motivation was to prevent the long error messages that can result from template instantiation. Instead the (in)validity of template is supposed to be easily detectable, so that an understandable error message can be given. Hence, it falls on the user to specify exactly which procedure they want.

Personally, I'm still undecided whether explicit instantiation is a good or bad decision. It seems like with a few minor modifications the syntax could allow automatic type deduction:

program main
  use reverse_module, only: reverse => reverse_tmpl(*) :: reverse   ! (*) as generic type place-holder
  !use reverse_moduly, only: reverse_tmpl
  !instantiate reverse_tmpl(integer), only: reverse
  integer :: a(5)
  a = [1,2,3,4,5]
  call reverse(a)   ! deduced reverse_tmpl(integer) :: reverse
  print *, a
end program

Since C++17, C++ allows programming user-defined deduction guides, to help the compiler in cases which are ambiguous, or when implicit instantiation is simply not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants