zlacker

[parent] [thread] 5 comments
1. stuart+(OP)[view] [source] 2025-12-13 19:18:06
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.
replies(1): >>lpil+n1
2. lpil+n1[view] [source] 2025-12-13 19:29:57
>>stuart+(OP)
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.
replies(1): >>stuart+641
◧◩
3. stuart+641[view] [source] [discussion] 2025-12-14 06:23:42
>>lpil+n1
Does that mean pass every needed function as a parameter? Or just don’t write generic functionality?
replies(1): >>lpil+Fd1
◧◩◪
4. lpil+Fd1[view] [source] [discussion] 2025-12-14 09:02:52
>>stuart+641
Yes, one would use higher order functions, as is common in Erlang, Elixir, OCaml, Elm, etc.
replies(1): >>shirog+1M1
◧◩◪◨
5. shirog+1M1[view] [source] [discussion] 2025-12-14 15:50:21
>>lpil+Fd1
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
replies(1): >>lpil+UM1
◧◩◪◨⬒
6. lpil+UM1[view] [source] [discussion] 2025-12-14 15:57:25
>>shirog+1M1
OCaml's modules are not implicitly instantiated, so they provide the same DX and APIs as you would get in Gleam.

Elixir does have protocols, but they are extremely limited compared to type classes, traits, etc, and they're uncommonly used compared to writing concrete code.

[go to top]