Prelude should have a foldr function #116

Open
opened 2025-06-11 21:59:37 +00:00 by scott · 1 comment
Owner
No description provided.
Author
Owner

Here's foldr (which is not "fold from the right," but right-associative):

fn foldr {
	"Folds a list using, right-associatively."
	(f as :fn, []) -> []
	(f as :fn, xs as :list) -> foldr (f, xs, f ())
	(f as :fn, [], root) -> []
	(f as :fn, xs as :list, root) -> loop (root, first (xs), rest (xs)) with {
		(prev, curr, []) -> f (curr, prev)
		(prev, curr, remaining) -> recur (
			f (curr, prev)
			first (remaining)
			rest (remaining)
		)
	}
}
Here's `foldr` (which is not "fold from the right," but right-associative): ``` fn foldr { "Folds a list using, right-associatively." (f as :fn, []) -> [] (f as :fn, xs as :list) -> foldr (f, xs, f ()) (f as :fn, [], root) -> [] (f as :fn, xs as :list, root) -> loop (root, first (xs), rest (xs)) with { (prev, curr, []) -> f (curr, prev) (prev, curr, remaining) -> recur ( f (curr, prev) first (remaining) rest (remaining) ) } } ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: twc/ludus#116
No description provided.