Skip to content

Instantly share code, notes, and snippets.

@akanehara
Last active December 10, 2015 05:08
Show Gist options
  • Save akanehara/4385309 to your computer and use it in GitHub Desktop.
Save akanehara/4385309 to your computer and use it in GitHub Desktop.
「fold書けないプログラマー」と聞いてドキっとしたので書いて確かめて気を落ち着かせる
let foldl f z xs =
let rec go acc xs =
match xs with
| [] -> acc
| x :: xs -> go (f acc x) xs
in go z xs;;
let foldr f z xs =
let rec go xs =
match xs with
| [] -> z
| (x :: rest) -> f x (go rest)
in go xs;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment