Std.ProofDirectedExtraction (Cure Standard Library v0.37.2)

View Source

A deliberately small proof-directed data pipeline.

Accepted(shape) stores data together with erased evidence for the indexed constructor that accepted it. Once the package exists, extract is total: matching the package refines the result of Sem, so there is no runtime validation branch and no Option in the accepted path.

Examples

use Std.ProofDirectedExtraction

extract(accepted_number_example())       # => 42
extract(accepted_flag_example())         # => true
remainder(contextual_example())          # => ['b']

Summary

Types

A contextual package analogous to an Encodes witness: the runtime remainder is retained, while erased Consumed evidence proves that it is the strict suffix of the original input selected by the indices.

Functions

Sample accepted flag package carrying true and erased FlagEvidence.

Sample accepted number package carrying 42 and erased NumberEvidence.

Sample contextual package consuming 'a' from ['a', 'b'] with remainder ['b'].

Extract the remainder ['b'] from contextual_example().

Totally extract the payload of an Accepted(shape) package at type Sem(shape).

Extract the boolean true from accepted_flag_example().

Extract the integer 42 from accepted_number_example().

Return the runtime remainder list carried by an AcceptedRemainder package.

Interpret a Shape tag as its target Cure value type (Int or Bool).

Types

type Accepted indices (shape: Shape)

 type Accepted indices (shape: Shape)
   AcceptedNumber : (value: Int) -> (@erased evidence : Evidence(NumberShape())) -> Accepted(NumberShape())
   AcceptedFlag : (value: Bool) -> (@erased evidence : Evidence(FlagShape())) -> Accepted(FlagShape())

type AcceptedRemainder indices (original: List(Char), remainder: List(Char))

 type AcceptedRemainder indices (original: List(Char), remainder: List(Char))
   AcceptedRemainderValue : (value: Char) -> (rest: List(Char)) -> (@erased evidence : Consumed(Char, True, rest, original)) -> AcceptedRemainder(original, rest)

A contextual package analogous to an Encodes witness: the runtime remainder is retained, while erased Consumed evidence proves that it is the strict suffix of the original input selected by the indices.

type Evidence indices (shape: Shape)

 type Evidence indices (shape: Shape)
   NumberEvidence : Evidence(NumberShape())
   FlagEvidence : Evidence(FlagShape())

enum Shape

 enum Shape
   NumberShape
   FlagShape

Functions

accepted_flag_example() -> Accepted(FlagShape())

 fn accepted_flag_example() -> Accepted(FlagShape())

Sample accepted flag package carrying true and erased FlagEvidence.

accepted_number_example() -> Accepted(NumberShape())

 fn accepted_number_example() -> Accepted(NumberShape())

Sample accepted number package carrying 42 and erased NumberEvidence.

contextual_example() -> AcceptedRemainder(Cons('a', Cons('b', Nil())), Cons('b', Nil()))

 fn contextual_example() -> AcceptedRemainder(Cons('a', Cons('b', Nil())), Cons('b', Nil()))

Sample contextual package consuming 'a' from ['a', 'b'] with remainder ['b'].

contextual_remainder_example() -> List(Char)

 fn contextual_remainder_example() -> List(Char)

Extract the remainder ['b'] from contextual_example().

extract(shape: Shape, accepted: Accepted(shape)) -> Sem(shape)

 fn extract(shape: Shape, accepted: Accepted(shape)) -> Sem(shape)

Totally extract the payload of an Accepted(shape) package at type Sem(shape).

extract_flag_example() -> Bool

 fn extract_flag_example() -> Bool

Extract the boolean true from accepted_flag_example().

extract_number_example() -> Int

 fn extract_number_example() -> Int

Extract the integer 42 from accepted_number_example().

remainder(original: List(Char), rest: List(Char), accepted: AcceptedRemainder(original, rest)) -> List(Char)

 fn remainder(original: List(Char), rest: List(Char), accepted: AcceptedRemainder(original, rest)) -> List(Char)

Return the runtime remainder list carried by an AcceptedRemainder package.

Sem(shape: Shape) -> Type

 fn Sem(shape: Shape) -> Type

Interpret a Shape tag as its target Cure value type (Int or Bool).