Std.Data.Suffix (Cure Standard Library v0.37.2)

View Source

A proof that rem is a suffix of orig, indexed by whether at least one element was consumed. This is the foundation of total lexers and parsers: recursive drivers may descend only after receiving a Consumed(..., True, ...) witness.

The indices are compile-time information. Runtime parsers carry their remainder directly; later slices erase/compact the witness while retaining the kernel-checked strictness relationship.

Examples

use Std.Data.Suffix

let empty_step = same([1, 2])
let one_step = drop(0, empty_step)
trans(one_step, same([1, 2]))

Summary

Types

Accessibility of the strict-suffix relation. A driver may recurse on any rest only after applying this witness with a proof that rest consumed at least one element from orig.

One parser transition. Success existentially carries its remainder while the dependent proof ties that remainder back to the original input. Failure is polymorphic in the consumption indices, so callers retain the strictness promised by the parser even when no value is produced.

Functions

Extend a suffix proof across one discarded head. Regardless of the inner proof's strictness, the result is now known to have consumed input.

Reflexivity: consuming nothing leaves the original input unchanged.

Transitivity. Sequencing two consumers is strict when either consumer is strict. The escaped or is an ordinary imported type-level function.

Types

type Acc(t) indices (orig: List(t))

 type Acc(t) indices (orig: List(t))
   MkAcc : (descend: ((rest: List(t)) -> Consumed(t, True, rest, orig) -> Acc(t, rest))) -> Acc(t, orig)

Accessibility of the strict-suffix relation. A driver may recurse on any rest only after applying this witness with a proof that rest consumed at least one element from orig.

type Consumed(a) indices (strict: Bool, rem: List(a), orig: List(a))

 type Consumed(a) indices (strict: Bool, rem: List(a), orig: List(a))
   Same : (xs: List(a)) -> Consumed(a, False, xs, xs)
   Drop : (head: a) -> Consumed(a, strict, rem, orig) -> Consumed(a, out, rem, Cons(head, orig))

type Step(t, e, a) indices (strict: Bool, orig: List(t))

 type Step(t, e, a) indices (strict: Bool, orig: List(t))
   Succ : (value: a) -> (rest: List(t)) -> Consumed(t, strict, rest, orig) -> Step(t, e, a, strict, orig)
   Fail : (error: e) -> Step(t, e, a, strict, orig)

One parser transition. Success existentially carries its remainder while the dependent proof ties that remainder back to the original input. Failure is polymorphic in the consumption indices, so callers retain the strictness promised by the parser even when no value is produced.

Functions

drop(a: Type, strict: Bool, rem: List(a), orig: List(a), head: a, proof: Consumed(a, strict, rem, orig)) -> Consumed(a, True, rem, Cons(head, orig))

 fn drop(a: Type, strict: Bool, rem: List(a), orig: List(a), head: a, proof: Consumed(a, strict, rem, orig)) -> Consumed(a, True, rem, Cons(head, orig))

Extend a suffix proof across one discarded head. Regardless of the inner proof's strictness, the result is now known to have consumed input.

same(a: Type, xs: List(a)) -> Consumed(a, False, xs, xs)

 fn same(a: Type, xs: List(a)) -> Consumed(a, False, xs, xs)

Reflexivity: consuming nothing leaves the original input unchanged.

trans(a: Type, left: Bool, right: Bool, orig: List(a), mid: List(a), rem: List(a), first: Consumed(a, left, mid, orig), second: Consumed(a, right, rem, mid)) -> Consumed(a, `or`(left, right), rem, orig)

 fn trans(a: Type, left: Bool, right: Bool, orig: List(a), mid: List(a), rem: List(a), first: Consumed(a, left, mid, orig), second: Consumed(a, right, rem, mid)) -> Consumed(a, `or`(left, right), rem, orig)

Transitivity. Sequencing two consumers is strict when either consumer is strict. The escaped or is an ordinary imported type-level function.