Zulip Chat Archive

Stream: Is there code for X?

Topic: Folding over multiple lists?


JJ (Jan 01 2025 at 22:14):

i find myself using racket's varadic fold a lot. it looks like List.foldl takes strictly one list, however. I suspect the answer is "use List.zip" - but does there happen to exist a fold that can take in an arbitrary number of lists, like so?

(foldl
  (λ (a b acc) (+ acc (abs (- a b))))
  0 (sort l1 <) (sort l2 <))

Johan Commelin (Jan 02 2025 at 09:53):

Not that I'm aware of. What would the type signature be?

Tomas Skrivan (Jan 02 2025 at 17:32):

It should be possible to implement using typeclasses similar to HasUncurry.uncurry that can take function of arbitrary arity.


Last updated: May 02 2025 at 03:31 UTC