Ich verwende FParsec und versuche, den resultierenden Wert an eine Variable in FSI zu binden. Ich habe versucht, mit den folgenden:So extrahieren Sie einen FParsec-Ergebniswert in eine Variable in FSI
> run pint32 "3";; // succeeds
val it : ParserResult<int32,unit> = Success: 3
> let x = run pint32 "3";;
val x : ParserResult<int32,unit> = Success: 3
> x;; // I bind the result to x
val it : ParserResult<int32,unit> = Success: 3
> let Success(y, _, _) = x;; //It looks like I can extract the value...
val Success : y:'a * 'b * 'c -> ParserResult<int32,unit>
> y;;
...error FS0039: The value or constructor 'y' is not defined
Es scheint, zu binden und dann vergessen Sie es, aber ich nehme an, ich bin etwas fehlt, da der folgende Destrukturierung funktioniert:
> type AB = A of int | B
let aa = A 1
let A a = aa;;
type AB =
| A of int
| B
val aa : AB = A 1
val A : a:'a -> AB
> a;;
val it : int = 1
Und die folgende Funktion scheint in der Lage den Wert mit einer Spiel-Anweisung extrahieren (obwohl ich den Fehlertyp auf dem Parser je ändern müssen würde):
> let extract p str =
match run p str with
| Success(result, _, _) -> result
| Failure(errorMsg, _, _) -> 3
let z = extract pint32 "3"
z;;
val extract : p:Parser<int,unit> -> str:string -> int
val z : int = 3
val it : int = 3
Was bin ich Missverständnis?