Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy assoc functions to OCaml stdlib? #59

Open
tekknolagi opened this issue Nov 7, 2018 · 1 comment
Open

Proxy assoc functions to OCaml stdlib? #59

tekknolagi opened this issue Nov 7, 2018 · 1 comment

Comments

@tekknolagi
Copy link

tekknolagi commented Nov 7, 2018

let rec lookup x = function

Many of the functions in assoc.ml can be proxied to OCaml stdlib:

  • Assoc.lookup => List.assoc_opt
  • Assoc.remove => List.remove_assoc
  • Assoc.iter => List.iter (has been done)
  • Assoc.kmap => List.map
  • Assoc.fold_left => List.fold_left (has been done)
  • Assoc.fold_right => List.fold_right (has been done)
  • Assoc.length => List.length (has been done)

and so on. Is there a reason these are re-implemented by hand?

@matijapretnar
Copy link
Owner

I don't recall exactly, but my guess is:

  • List.assoc_opt wasn't around until recently
  • We probably didn't bother to look for List.remove_assoc
  • If I recall correctly, List.map used to be implemented as
let rec map f = function
| [] -> []
| x :: xs -> f x :: map f xs

and then it depends on the byte/native code whether f x or map f xs is evaluated first. Since we used quite some effectful functions f in the implementation, we decided to write our own implementation that guarantees the order of evaluation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants