What is the difference between these two type definitions in OCaml

type t1 = A of int * stringand type t2 = A of (int * string)are they different or the same?

In this functional programming textbook , slide 6, he says

In OCaml, options take several arguments, rather than taking tuples as arguments: A from int * string is different from A of (int * string). But it doesn’t matter if you haven’t bitten it.

But I do not see any difference, except for a pair of brackets.

+3
source share
1 answer

Try the following:

type t1 = A of int*int
type t2 = B of (int*int)
let x = (1,2) in A x (* does not work *)
let x = (1,2) in B x (* works *)

That is, it Bis a constructor that expects 1 argument (namely, a tuple containing two integers), and Ais a constructor that takes 2 arguments (supplied as comma-separated elements in brackets).

0

All Articles