logoalt Hacker News

kace91yesterday at 5:49 PM4 repliesview on HN

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


Replies

threethirtytwoyesterday at 5:54 PM

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.

chongliyesterday at 6:42 PM

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).

lpilyesterday at 7:27 PM

Gleam does have generics.

nerdponxyesterday at 8:12 PM

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.