Re:Modern programming languages require generics
by ayende on Monday May 23, 2022 @06:45AM
(#31477345)
Can you explain what you mean by generics modules?
[ Parent
| on HN ]
Re:Modern programming languages require generics
by Rochus on Monday May 23, 2022 @11:02AM
(#31479898)
Here is an example: https://oberon-lang.github.io/, see section Generic Programming; note how the modules have type parameters and how generic module is instantiated by the import declaration in the example of section Object Oriented Programming.
Here is the specification: https://github.com/oberon-lang/specification/blob/master/The...
Here is a discussion why it is designed like this: https://oberon-lang.github.io/2021/07/17/considering-generic...
Re:Modern programming languages require generics
by mncharity on Monday May 23, 2022 @07:34PM
(#31486171)
Thanks for this. By coincidence, I was sketching out a polymorphism kludge this evening, and this was food for thought.
Re:Modern programming languages require generics
by ayende on Monday May 23, 2022 @11:41AM
(#31480468)
That reminds me very strongly how Zig does it
Re:Modern programming languages require generics
by Rochus on Monday May 23, 2022 @11:59AM
(#31480697)
I'm not familiar with Zig, but a quick look at https://ziglang.org/documentation/master/#Generic-Data-Struc... makes me doubt that Zig does genericity on module level; looks rather like parametric polymorphism.
Re:Modern programming languages require generics
by mncharity on Monday May 23, 2022 @07:31PM
(#31486154)
Not GP, and I'm just surfing unfamiliar docs, but it looks like, yes, there's general parameter polymorphism,[1] but also "modules" presented as structs,[2] and the polymorphism of struct constructors can have nontrivial impacts[3](eg Map(KeyType,void) loses value setters). Fwiw.
[1] https://ziglang.org/documentation/master/#comptime "Compile-time parameters is how Zig implements generics. It is compile-time duck typing." [2] https://ziglang.org/documentation/master/#import [3] https://ziglang.org/documentation/master/#void "By using void as the type of the value, the hash map entry type has no value field, and thus the hash map takes up less space. Further, all the code that deals with storing and loading the value is deleted, as seen above."