mirror of
https://github.com/HigherOrderCO/Kind.git
synced 2024-09-11 20:47:25 +03:00
20 lines
437 B
Plaintext
20 lines
437 B
Plaintext
Parser.repeat
|
|
: ∀(n: Nat) ∀(A: *) ∀(p: (Parser A))
|
|
(Parser (List A))
|
|
= λn λA λp
|
|
let P = λx (Parser (List A))
|
|
let succ = λn.pred
|
|
(Parser.bind
|
|
A
|
|
(List A)
|
|
p
|
|
λhead
|
|
(Parser.bind
|
|
(List A)
|
|
(List A)
|
|
(Parser.repeat n.pred A p)
|
|
λtail (Parser.pure (List A) (List.cons A head tail))
|
|
)
|
|
)
|
|
let zero = (Parser.pure (List A) (List.nil A))
|
|
(~n P succ zero) |