janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

Request: Int.post_incr #121

Closed johnyob closed 2 years ago

johnyob commented 2 years ago

As with incr (which pre-increments an int ref), it would be extremely useful to have a post-increment function post_incr:

let post_incr r = 
  let result = !r in
    incr r;
    result
bcc32 commented 2 years ago

FWIW, incr doesn't pre-increment an int ref, it just does the increment step. Either way, you have to read the value in a separate step from incrementing it.

Can you give an example where this would be useful? I have a hard time thinking up where this might be needed in idiomatic OCaml code.

bcc32 commented 2 years ago

I think we're pretty unlikely to add this, so I'm closing this issue. If there is a compelling use case we might not be considering, you can reopen the issue.