roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.06k stars 287 forks source link

Folding function composition over a list of closures #851

Open rtfeldman opened 3 years ago

rtfeldman commented 3 years ago

@exists-forall pointed out that the Roc equivalent of this pseudocode likely has a bug:

foldl([(+ x), (+ y), (+ z)], identity, compose) 

(where x, y, and z are being closed over)

The problem is that the size of the closure returned by compose depends on the length of the list, which can't be known until runtime.

Morphic solved this by boxing the closed-over data returned by (a function like) compose, which is likely what Roc should do too.

folkertdev commented 3 years ago

additional notes