OCaml中的参数化类型

OCaml中的参数化类型,ocaml,parameterized-constructor,Ocaml,Parameterized Constructor,我找了一段时间,找不到解决办法。这可能是一个我无法理解的简单语法问题 我有一种类型: # type ('a, 'b) mytype = 'a * 'b;; 我想创建一个string sum类型的变量 # let (x:string string mytype) = ("v", "m");; Error: The type constructor mytype expects 2 argument(s), but is here applied to 1 argument(s) $ oc

我找了一段时间,找不到解决办法。这可能是一个我无法理解的简单语法问题

我有一种类型:

# type ('a, 'b) mytype = 'a * 'b;;
我想创建一个
string sum
类型的变量

# let (x:string string mytype) = ("v", "m");;
Error: The type constructor mytype expects 2 argument(s),
   but is here applied to 1 argument(s)
$ ocaml
        OCaml version 4.01.0

# type ('a, 'b) mytype = 'a * 'b;;
type ('a, 'b) mytype = 'a * 'b
# let x = ("v", "m");;
val x : string * string = ("v", "m")
# (x : (string, string) mytype);;
- : (string, string) mytype = ("v", "m")
我尝试过用不同的方法在类型参数周围加括号,我得到了几乎相同的错误

但是,它只适用于单参数类型,所以我想有些语法我不知道

# type 'a mytype2 = string * 'a;;
# let (x:string mytype2) = ("hola", "hello");;
val x : string mytype2 = ("hola", "hello")
有人能告诉我如何使用两个参数进行此操作吗

let (x: (string, string) mytype) = ("v", "m");;
也就是说,
mytype
参数是一对。您甚至可以删除不需要的括号:

let x: (string, string) mytype = "v", "m";;

值得注意的是,您的type
mytype
只是一对的同义词,因为它没有任何构造函数。所以你可以说,让x=(“v”,“m”)


关键是这两种类型
string*string
(string,string)mytype
是相同的类型。

谢谢!我不是这样使用它,我只是想弄清楚如何创建参数化类型的东西。pair同义词只是这种类型的一个简单示例。