#OCaml signatures for `iter`:

lst ~f
f lst
()
(fold's signature)
~f lst

whyyyyyyyyy

@ELLIOTTCABLE Not just. I wish I could just blame one group, but noooo

Stdlib.Either: left:('a -> unit) -> right:('b -> unit) -> ('a, 'b) t -> unit

Eio.Fiber.List: ('a -> unit) -> 'a list -> unit

rescript compiler: t -> (elt -> unit) -> unit

liquidsoap: (int -> t -> unit) -> unit

dune's resolve: 'a list -> f:('a -> unit t) -> unit t

infer: t -> elt Iter.t

Instabug's infer: 'a t -> f:('a -> unit) -> unit

@hrefna @ELLIOTTCABLE 'iter f lst' vs. 'iter lst f' is because of two conflicting idioms: partial application (let print_list = List.iter f) vs. anonymous functions:
List.iter lst (fun x ->
<a bunch of code>
)
For the other examples, I'm not sure what you were expecting. Creating tuples is expensive, so iterating over a key/value container won't have the same signature as iterating over a set (e.g. Hashtbl.iter takes (fun key value -> ...), not (fun (key, value) -> ...)). It's not something that's bothering me, so it must be a cultural thing 🙂

Follow

@hrefna @ELLIOTTCABLE also, the labeled versions of iter were designed to allow flipping the arguments depending on the situation. I don't like to use labels for such simple functions, though.
In recent years, we were blessed with the pipeline operator `|>` , which makes the original List.iter reasonable again without having to resort to labels:
lst |> List.iter (fun x ->
<a bunch of code>
)

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.