In standard library, add
function has the following signature:
val add : elt -> t -> t
So I can add elements with pipeline operator:
Set.empty |> add elt1 |> add elt2
However, when I switch to Core, I notice that the signature for add has become to:
val add : ('a, 'cmp) t -> 'a -> ('a, 'cmp) t
Now set becomes the first parameter. The old pipeline-style does not apply to it anymore.
What would be the idiomatic way to add an element using Core Set?
Do not use the pipeline to obfuscate function application!
The pipeline has good reasons to exist, namely to build pipelines, but in your example, you are merely abusing and obfuscate your code.
If you just want to add two elements to a set, just write
It is perfectly clean an legible. If you have more elements to add, you can improve readability by using a fold-function:
We could speculate that Jane Street changed the signature of
Set.add
precisely to use it withList.fold_left
which is tail-recursive, while theList.fold_right
that should be used with the sets from the standard library is not tail recursive.