mirror of
https://github.com/HigherOrderCO/Kind.git
synced 2024-09-11 19:17:27 +03:00
12 lines
400 B
Plaintext
12 lines
400 B
Plaintext
Parser.variant
|
|
: ∀(A: *)
|
|
∀(variants: (List (Parser.Guard A)))
|
|
(Parser A)
|
|
= λA λvariants
|
|
let P = λx(Parser A)
|
|
let cons = λvariant λothers
|
|
(Pair.get (Parser Bool) (Parser A) variant (Parser A) λguard λparser
|
|
(Parser.bind Bool A guard λsuccess
|
|
(Bool.if success (Parser A) parser (Parser.variant A others))))
|
|
let nil = (Parser.fail A "error")
|
|
(~variants P cons nil) |