You cannot create sets of heterogeneous elements. Of course, you can define a type to unify types if you know them beforehand. It looks like you are doing this, and it could be a recursive type defined by:
type ('a,'b) r = | L of 'a | N of (('a,'b) r * 'b)
Thus, your examples will be built as
N (L a,1) N ( N (L a,1),1) N ( N ( N (L a,1),1),1)
Then you simply create an Ordered module to enable the comparison function.
In the case of creating a Cartesian product, you will not deal with heterogeneous elements at the moment, but with a tuple of the previous type. This will require a new Ordered module for comparison.
nlucaroni
source share