The answer provided by @Foole is good, but the comment gives the impression that you don't like to βdeclareβ the temporary variable first . It can really seem cumbersome if all you want to do is pull out the first value and then pass it to another function.
There is no built-in object that I know about that allows you to do this automatically. Suppose the above type of Corner is a degenerate case of the Discriminatory Union (DU). Usually DUs have more cases, and they are often heterogeneous in shape.
There may be good reasons for having the same DU, such as Corner , but it often makes sense to also provide various βhelperβ functions to make working with this type smoother.
In the case of the Corner type, you can define functions such as:
let cornerX (Corner(x, _)) = x let cornerY (Corner(_, y)) = y
Here, I suggested that Corner models the coordinate, but if you want, you can also name the functions fst and snd . You can also put them in a dedicated module if you prefer this.
This will allow you to retrieve and pass the value from the Corner value without the hassle of a temporary variable:
> corner |> cornerX |> ((*) 10) |> string;; val it : string = "10"
where Corner defined as in OP.
source share