我定義了兩個記錄類型如下:訪問成員時,歧記錄類型有共同的標籤
(* in module A*)
type reg = {name: string; mutable value: Big_int.big_int}
type exp = Reg of reg | Other
(* in module B*)
type abstr = Top | Bot | Elt of int
type register = {name: string; mutable value: abstr}
在模塊B,我有一個名單,我稱之爲l
,exp
,我正在做一個模式匹配。所以,我有這樣的事情:
List.fold_left (fun l elt ->
let str =
match elt with
| A.Reg r -> r.name
| _ -> failwith "exception" in
[email protected][{name = str; value = Bot}]) [] l
但我得到以下錯誤:表達的類型爲A.reg但預計類型寄存器的。看起來模塊A中的定義被模塊B中的定義所隱藏。如果是,爲什麼會這樣?有人可以解釋嗎?
你可以嘗試用'A.Reg'代替'A.reg'嗎? – dkim 2012-08-06 14:54:55
這就是我在代碼中實際使用的內容 – 2012-08-06 15:11:28