For [1]:
# let make pair int (x:int) (y:int) = x,y ;;
val make_pair_int : int -> int -> int * int = <fun>
How do you read the typing information output? In other languages, I find being able to construct a cogent, English sentence out of the syntax or the printouts to be critical in understanding what’s going on. What’s the sentence for the above OCaml statement?
Could someone diagram out the printout so as to correlate the typing information back into English? Like:
val make_pair_int : int -> int -> int * int = <fun>
| | | | | \_____/ \__/
| | | | | | ` is a function
| | | | | ` a tuple of integers
| | | | `
| | | `
| | `
| `
` symbol make_pair_int is bound to
This is just the curried version of your function. The reading of such a function depends on how comfortable you are with curried notation for functions.
The gist is to consider that taking two arguments is a completely different notion from taking a pair of arguments in the sense that the pair makes a reference to a specific type constructor (what is hidden under the
*and,symbols in your ocaml snippet).What do you do if you do not want to make a reference to a pairing (or tupling, if you want an arbitrary array of arguments) construct ? The curried answer to that question is the one that makes use of higher-order functions:
With the implicit convention that this curried interpretation (and the notation that comes with it) is the admitted way of thinking of a function taking several arguments, you can just count the number of arrows in the type, and consider those before the last one as “the arguments” of your function.