Skip to content

Instantly share code, notes, and snippets.

@cowlike
Created November 10, 2023 16:49
Show Gist options
  • Save cowlike/9758eae1f7c3f8425bab917dcb52cf92 to your computer and use it in GitHub Desktop.
Save cowlike/9758eae1f7c3f8425bab917dcb52cf92 to your computer and use it in GitHub Desktop.
continuation-based recursion
let rec reduce' (f: 'a -> 'a -> 'a) init xs cont =
match xs with
| [] -> cont init
| x :: xs -> reduce' f init xs (fun y' -> cont <| f x y')
reduce' (+) 0 [1..5] id
reduce' (+) 0UL [1UL..1000000UL] id
reduce' (+) 0UL [1UL..999999UL] id
reduce' (+) 0UL [1UL..100_000_000UL] id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment