zlacker

[parent] [thread] 4 comments
1. lpil+(OP)[view] [source] 2025-12-13 19:29:57
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+J21
2. stuart+J21[view] [source] 2025-12-14 06:23:42
>>lpil+(OP)
Does that mean pass every needed function as a parameter? Or just don’t write generic functionality?
replies(1): >>lpil+ic1
◧◩
3. lpil+ic1[view] [source] [discussion] 2025-12-14 09:02:52
>>stuart+J21
Yes, one would use higher order functions, as is common in Erlang, Elixir, OCaml, Elm, etc.
replies(1): >>shirog+EK1
◧◩◪
4. shirog+EK1[view] [source] [discussion] 2025-12-14 15:50:21
>>lpil+ic1
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+xL1
◧◩◪◨
5. lpil+xL1[view] [source] [discussion] 2025-12-14 15:57:25
>>shirog+EK1
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]