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. stuart+Gh[view] [source] 2025-12-13 19:18:06
>>mono44+gg
The answer I’ve seen is “just pass structs of functions around”, which is just one step more explicit than the implicit version we’re all use to, but honestly I kinda like it to free ourselves of all the ceremony around generics.
◧◩◪
3. lpil+3j[view] [source] 2025-12-13 19:29:57
>>stuart+Gh
It’s discouraged to pass around structs of functions to replicate type classes in Gleam. Instead the preference is to not type class style patterns in your projects, favouring a concrete style instead.
◧◩◪◨
4. stuart+Ml1[view] [source] 2025-12-14 06:23:42
>>lpil+3j
Does that mean pass every needed function as a parameter? Or just don’t write generic functionality?
◧◩◪◨⬒
5. lpil+lv1[view] [source] 2025-12-14 09:02:52
>>stuart+Ml1
Yes, one would use higher order functions, as is common in Erlang, Elixir, OCaml, Elm, etc.
◧◩◪◨⬒⬓
6. shirog+H32[view] [source] 2025-12-14 15:50:21
>>lpil+lv1
At least half of those languages (Elixir and OCaml) have some sort of mechanism for ad hoc polymorphism (elixir has behaviors and protocols, OCaml has higher order modules) so I feel like the comparison doesn't work that well personally
[go to top]