Skip to content

Instantly share code, notes, and snippets.

@michiakig
Created July 17, 2013 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save michiakig/6022274 to your computer and use it in GitHub Desktop.
Save michiakig/6022274 to your computer and use it in GitHub Desktop.
type 'a monoid = {zero : 'a; plus : 'a -> 'a -> 'a}
let sum (m : 'a monoid) (l : 'a list) : 'a = List.fold_left m.plus m.zero l
let string_summer = sum {zero = ""; plus = (^)}
let int_summer = sum {zero = 0; plus = (+)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment