# RFC: \`for...in\` construct

**URL:** <https://discuss.ocaml.org/t/rfc-for-in-construct/17250>\
**Category:** Ecosystem\
**Tags:** compiler\
**Created:** [September 14, 2025, 4:32pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250 "2025-09-14T16:32:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [September 14, 2025, 4:32pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/1 "2025-09-14T16:32:08Z")

</div>

Hello,

Here’s [an RFC](https://github.com/ocaml/RFCs/pull/56) I drafted for adding a `for...in` construct to the language. Feedback is welcome here 🙂

Some reservations were already voiced [here](https://caml.zulipchat.com/#narrow/channel/527805-compiler/topic/.60for.20.2E.2E.20in.60.20in.20OCaml/with/539419833), and acknowledged in the RFC.

---

<div class="post-metadata">

**Author:** ![andreypopp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/andreypopp/32/97_2.png) [@andreypopp](https://discuss.ocaml.org/u/andreypopp)\
**Post date:** [September 15, 2025, 2:12pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/2 "2025-09-15T14:12:57Z")

</div>

I was hoping it adds comprehensions/LINQ to OCaml but it’s a syntax sugar for `iter`. 🙂

---

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [September 15, 2025, 2:59pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/3 "2025-09-15T14:59:54Z")

</div>

This could be done nicely with a ppx no?

---

<div class="post-metadata">

**Author:** ![andreypopp](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/andreypopp/32/97_2.png) [@andreypopp](https://discuss.ocaml.org/u/andreypopp)\
**Post date:** [September 15, 2025, 3:17pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/4 "2025-09-15T15:17:15Z")

</div>

`for…in` could also be done “nicely” with ppx then

---

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [September 15, 2025, 3:59pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/5 "2025-09-15T15:59:16Z")

</div>

To a lesser extent (I think) but yes. I mean I’d be happy with comprehension in OCaml too, but questions about “which data structure” does one build, and how do you specify that are unclear to me.

I’m not going to draft more than one RFC at a time, but feel free to do so if you have a clear idea of implementation

---

<div class="post-metadata">

**Author:** ![vlaviron](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vlaviron](https://discuss.ocaml.org/u/vlaviron)\
**Post date:** [September 15, 2025, 4:52pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/6 "2025-09-15T16:52:22Z")

</div>

List and array comprehensions are already present in OxCaml, if you’re interested (I haven’t used them myself, but they’re documented [here](https://oxcaml.org/documentation/comprehensions/01-intro/)).

---

<div class="post-metadata">

**Author:** ![giltho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/giltho/32/3521_2.png) [@giltho](https://discuss.ocaml.org/u/giltho)\
**Post date:** [September 15, 2025, 5:23pm UTC](https://discuss.ocaml.org/t/rfc-for-in-construct/17250/7 "2025-09-15T17:23:47Z")

</div>

Nice! Didn’t know about that feature of OxCaml, thank you 🙂  
I wonder if the mechanism can be transparently extended to other data structure (e.g. any data structure that can be `filter_map`ped)
