8
簡化後,我在OCaml的這個簡單的代碼:無法解構產品類型OCaml中
type int_pair = int * int;;
type a = A of int_pair;;
let extract (A x) = x;;
測試我extract
功能,它似乎工作:
# extract (A (1,2));;
- : int_pair = (1, 2)
我簡化它,所以它只需要一種類型:
type a' = A' of int * int;;
let extract' (A' x) = x;;
但我得到的錯誤:
Error: The constructor A' expects 2 argument(s),
but is applied here to 1 argument(s)
有趣的是,我可以構建的a'
值...
# A' (1,2);;
- : a' = A' (1, 2)
...我只是不能解構它們。爲什麼?