Created
July 17, 2013 16:40
-
-
Save michiakig/6022274 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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