ocaml-containers icon indicating copy to clipboard operation
ocaml-containers copied to clipboard

`CCOption.bind` and `CCParse.bind` have inconsistent parameter orders; should be unified?

Open torch-and-blanket opened this issue 11 months ago • 3 comments

Depending on this project's attitude toward breaking changes, it may be worth changing CCOption.bind : 'a option -> ('a -> 'b option) -> 'b option to align with the current type of CCParse.bind : ('a -> 'b CCParse.t) -> 'a CCParse.t -> 'b CCParse.t. I suggest this, rather than vice versa, to facilitate patterns like return x |> bind f |> bind g, following the general principle that a function's final argument should be the argument to which that function is least likely to be "partially" applied.

Making the types of all bind functions consistent throughout the library will make it easier to write functors that expect monads as well and help keep interfaces to CC modules predictable. As far as I can tell, these two are the only instances of bind throughout containers.

torch-and-blanket avatar Jan 01 '25 20:01 torch-and-blanket

I think that means that CCParse.bind is the wrong one, tbh. In general I use the infix operators anyway.

c-cube avatar Jan 01 '25 20:01 c-cube

Thanks, quick reply!

Are you open to one of those functions changing, then? At least in principle?

I'm also curious what your reason for preferring 'a t -> ('a -> 'b t) -> 'b t is, over the other way round.

torch-and-blanket avatar Jan 01 '25 21:01 torch-and-blanket

I think I started this way because of Lwt.bind a long time ago. As I say, it's better to use let* these days :-).

c-cube avatar Jan 03 '25 18:01 c-cube