Kind/book/Parser.repeat.kind2
Victor Taelin 85ad65b026 use-notation
Now, there are two local binders:

let x = ...
use x = ...

The 'let' binder will create a local definition, type-check it, and
assign a name to it. When compiled, it will create 'dup' nodes.

The 'use' binder is just an alias. It will not bind a new variable, and,
when compiled, will create inline copies. Also, for type-checking, it
allows creating aliases that are definitionaly equal for the checker.
2024-03-08 17:39:37 -03:00

20 lines
437 B
Plaintext

Parser.repeat
: ∀(n: Nat) ∀(A: *) ∀(p: (Parser A))
(Parser (List A))
= λn λA λp
use P = λx (Parser (List A))
use 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))
)
)
use zero = (Parser.pure (List A) (List.nil A))
(~n P succ zero)