Quelle est la meilleure façon de créer une exception qui contient un type dans lequel il est lancé en F #? Ce qui suit ne fonctionne pas:Comment définir une relation récursive entre un type d'exception et un autre type?
// 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)
Merci!
Merci, fonctionne parfaitement – Rickard