3
type my_sum = {a : type_a}/{b : type_b}
mylist = [{field_only_in_a = "test"} : type_a,{haha=3 ; fsd=4} : type_b]
名單我想這樣做:
result = List.find(a -> match a with
| {a = _} -> true
| _ -> false
end,
mylist)
if Option.is_some(result) then
Option.some(Option.get(result).field_only_in_a)
else
Option.none
就像你所看到的,發現後我一定要得到的東西type_a
但編譯時,我得到的是:
Record has type
{ a : type_a }/{ b : type_b } but field access expected it to have type
{ field_only_in_a: 'a; 'r.a }
Hint:
You tried to access a sum type with several cases as a record.
我怎麼能說給compilator,我有分機只有一種類型的總和類型,我有很好的類型來訪問記錄......?