Remix.run Logo
kace91 13 hours ago

Perhaps this is a silly question but how do you do functional with no generics? Arent they pretty much required for map/reduce/filter?

threethirtytwo 13 hours ago | parent | next [-]

Sorry my comment was wrong. It’s been a while when I messed with gleam and I remember it was missing a critical thing but I misremembered what it was.

Gleam doesn’t support interfaces. Not generics. You are completely right.

chongli 12 hours ago | parent | prev | next [-]

There are multiple levels of possible generics at play here: the container type and the element type. You can have a map/reduce/filter that operate on any element type (generic elements) while still being specialized to linked lists. On the other hand, you might prefer a generic map that can operate on any container type and any element type, so that you can use the same map method and the same function to map over arrays of numbers, sets of numbers, lists of numbers, trees of numbers, or even functions of numbers!

Haskell allows both sorts of generics. In Haskell parlance they call this higher-kinded polymorphism and the generic version of map they call fmap (as a method of the class Functor).

lpil 12 hours ago | parent | prev | next [-]

Gleam does have generics.

nerdponx 11 hours ago | parent | prev [-]

Most Scheme implementations don't have generics, and you have to deal with a different map function for every data structure.

Gauche has a generic sequence interface which is great, and it's one of the reasons as a Python user I like Gauche as my "daily driver" Scheme.