zlacker

[return to "I tried Gleam for Advent of Code"]
1. mono44+gg[view] [source] 2025-12-13 19:05:07
>>tymsca+(OP)
I've looked at Gleam before but it didn't seem to have any mechanism for dynamic dispatch like interfaces or type classes. Did it change in the meantime?
◧◩
2. lpil+Ih[view] [source] 2025-12-13 19:18:36
>>mono44+gg
Gleam has first class functions, so it has dynamic dispatch.

Both of type classes and interfaces desugar to high order functions, so anything you write with them can be written with first class functions, though with a less concise API.

◧◩◪
3. the_du+6i[view] [source] 2025-12-13 19:21:13
>>lpil+Ih
What you are saying is: no, it doesn't.

Of course dynamic dispatch can be implemented in almost every language. The Linux kernel uses dynamic dispatch with C!

But that's a hack, not a language feature.

◧◩◪◨
4. array_+Qk1[view] [source] 2025-12-14 06:06:51
>>the_du+6i
It's not a "hack" because many language DO NOT let you store functions with state. Gleam does, I write PHP, and that does as well.

PHP has interfaces and whatnot, but a lot of the time I do polymorphism by just having a class that has Closure members. When you can arbitrarily pass around functions like that, it's basically equivalent to an interface or abstract class, with a bit more flexibility.

[go to top]