Created
January 4, 2017 19:52
-
-
Save zobar/95f37b98970a294ff3530e8797d8963e 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
| module Iter = struct | |
| type 'a t = { | |
| fold: 'b. ('b -> 'a -> 'b) -> 'b -> 'b | |
| } | |
| let empty = { | |
| fold = fun f accu -> accu | |
| } | |
| let pure a = { | |
| fold = fun f accu -> f accu a | |
| } | |
| let fold f a b = b.fold f a | |
| let append a b = { | |
| fold = fun f accu -> fold f (fold f accu a) b | |
| } | |
| let map f a = { | |
| fold = fun g accu -> fold (fun accu a -> g accu (f a)) accu a | |
| } | |
| let bind f a = { | |
| fold = fun g accu -> fold (fun accu a -> fold g accu (f a)) accu a | |
| } | |
| let ap f a = { | |
| fold = fun g accu -> fold (fun accu f -> fold g accu (map f a)) accu f | |
| } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment