Wednesday, April 15, 2009

Using the non-functional parts of OCaml is often creepy

I tried to use Map.iter a few times, but it was just creepy:
iter : (key -> 'a -> unit) -> 'a t -> unit

The function takes a function that takes a key, value, and updates some state, and then in the end you don't get anything back--just the updated state that lives somewhere else. Agh! I prefer to use Map.fold, which makes the state updating more explicit:
fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b

No comments: