定义(不分配)自定义类型的变量
Define (without assigning) variable of custom type
我定义了以下两种自定义类型:
type noeud = Lettre of (char * bool * arbre_lex)
and arbre_lex = noeud list
我可以轻松创建一个包含 1 noeud
元素的 arbre_lex
:
# let a = [ Lettre ('c', true, []) ];;
val a : noeud list = [Lettre ('c', true, [])]
Now how can I create an arbre_lex
custom type that consists of 0 noeud
elements?
这只是创建一个空列表,但它不是 arbre_lex
...
类型
# let b = [];;
val b : 'a list = []
而this似乎不起作用:
# let c : arbre_lex = [];;
Error: Syntax error
更新:我不知道发生了什么,但不知何故我做错了什么。正确的方法确实是:
# let d : arbre_lex = [];;
val d : arbre_lex = []
我定义了以下两种自定义类型:
type noeud = Lettre of (char * bool * arbre_lex)
and arbre_lex = noeud list
我可以轻松创建一个包含 1 noeud
元素的 arbre_lex
:
# let a = [ Lettre ('c', true, []) ];;
val a : noeud list = [Lettre ('c', true, [])]
Now how can I create an
arbre_lex
custom type that consists of 0noeud
elements?
这只是创建一个空列表,但它不是 arbre_lex
...
# let b = [];;
val b : 'a list = []
而this似乎不起作用:
# let c : arbre_lex = [];;
Error: Syntax error
更新:我不知道发生了什么,但不知何故我做错了什么。正确的方法确实是:
# let d : arbre_lex = [];;
val d : arbre_lex = []