創建一個包含從F#拋出的類型的異常的最佳方式是什麼?以下不起作用:如何定義異常類型和另一種類型之間的遞歸關係?
// this fails since HeaderInfo is not yet defined. Can't seem use the and-keyword
// on HeaderInfo
exception MissingHeader of string*HeaderInfo
type HeaderInfo =
{
DefaultHeaderIndices: Map<string, int>;
AdditionalStudyIndices: Map<string, int>;
VolumeIndex: int option;
}
with member this.GetCommonIndex(name) =
match this.DefaultHeaderIndices.TryFind(name) with
| Some(idx) -> idx
| None ->
match this.AdditionalStudyIndices.TryFind(name) with
| Some(idx) -> idx
| None ->
match this.VolumeIndex with
| Some(idx) when name = optionalHeader -> idx
| _ -> raise <| MissingHeader(name, this)
謝謝!
謝謝,完美的作品 – Rickard