Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created May 4, 2014 23:18
Show Gist options
  • Save AeroNotix/fbe36133e858349418f8 to your computer and use it in GitHub Desktop.
Save AeroNotix/fbe36133e858349418f8 to your computer and use it in GitHub Desktop.
module type S = sig
type 'a t
val fold : 'a t -> init:'acc -> f:('acc -> 'a -> 'acc) -> 'acc
end
module MyFolder = struct
type 'a t = (int * 'a) list
let fold (a : 'a t) ~init ~f =
let rec aux prev = function
| [] -> prev
| hd :: tl -> aux (f prev hd) tl in
aux init a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment