pub struct Hiding<'brand, N> { /* private fields */ }Expand description
Wrapper that allows a node to be “hidden” during program construction.
§Program construction
When a program is constructed in post-order, the parent node is created based on its children. We use this fact to introduce special branching logic:
- A
casenode with a left “hidden” child and a right non-hidden child becomesassertr. - A
casenode with a left non-hidden child and a right “hidden” child becomesassertl. - Otherwise, any node with “hidden” children becomes itself “hidden” with an updated CMR.
- Any node with non-hidden children remains unchanged.
The program can be extracted from the wrapper when construction is finished. The program is invalid if the root node is “hidden”.
§Wrapping
A node can be wrapped via Hiding::from to add hiding support.
A wrapped node can be converted into a “hidden” node via Hiding::hide.
Finally, a “hidden” node can be manually created via Hiding::hidden.
§Virtual hidden nodes
The wrapper merely simulates hidden nodes. At no point are actual hidden nodes created. To stress this fact, I write “hidden” in quotation marks.
Implementations§
Source§impl<'brand, N> Hiding<'brand, N>
impl<'brand, N> Hiding<'brand, N>
Create a “hidden” node with the given CMR.
To enable the construction of possible parent nodes, the inference context of the current program must be passed.
Sourcepub fn map_ref<M>(
&self,
mapfn: impl FnOnce(&N) -> M,
cmrfn: impl FnOnce(Cmr) -> Cmr,
) -> Hiding<'brand, M>
pub fn map_ref<M>( &self, mapfn: impl FnOnce(&N) -> M, cmrfn: impl FnOnce(Cmr) -> Cmr, ) -> Hiding<'brand, M>
If the node is not hidden, apply a function to the underlying node. If it is hidden, apply a function to its CMR.
Sourcepub fn map_ref_result<M, Err>(
&self,
mapfn: impl FnOnce(&N) -> Result<M, Err>,
cmrfn: impl FnOnce(Cmr) -> Cmr,
) -> Result<Hiding<'brand, M>, Err>
pub fn map_ref_result<M, Err>( &self, mapfn: impl FnOnce(&N) -> Result<M, Err>, cmrfn: impl FnOnce(Cmr) -> Cmr, ) -> Result<Hiding<'brand, M>, Err>
If the node is not hidden, apply a function to the underlying node. If it is hidden, do nothing.
Source§impl<'brand, N: HasCmr + CoreConstructible<'brand>> Hiding<'brand, N>
impl<'brand, N: HasCmr + CoreConstructible<'brand>> Hiding<'brand, N>
Sourcepub fn hide(self) -> Self
pub fn hide(self) -> Self
Replace the node, if any, with its CMR; replace its type arrow with a new free arrow.
Once hidden, a node’s original type arrow loses its original bounds. In effect, a hidden node is a completely separate node from its “original” node and is typechecked and shared independently.
Trait Implementations§
Source§impl<'brand, N: HasCmr + CoreConstructible<'brand>> CoreConstructible<'brand> for Hiding<'brand, N>
impl<'brand, N: HasCmr + CoreConstructible<'brand>> CoreConstructible<'brand> for Hiding<'brand, N>
fn iden(inference_context: &Context<'brand>) -> Self
fn unit(inference_context: &Context<'brand>) -> Self
fn injl(child: &Self) -> Self
fn injr(child: &Self) -> Self
fn take(child: &Self) -> Self
fn drop_(child: &Self) -> Self
fn comp(left: &Self, right: &Self) -> Result<Self, Error>
fn case(left: &Self, right: &Self) -> Result<Self, Error>
fn assertl(left: &Self, right: Cmr) -> Result<Self, Error>
fn assertr(left: Cmr, right: &Self) -> Result<Self, Error>
fn pair(left: &Self, right: &Self) -> Result<Self, Error>
fn fail(inference_context: &Context<'brand>, entropy: FailEntropy) -> Self
fn const_word(inference_context: &Context<'brand>, word: Word) -> Self
fn jet(inference_context: &Context<'brand>, jet: &dyn Jet) -> Self
fn arrow(&self) -> &Arrow<'brand>
Source§fn inference_context(&self) -> &Context<'brand>
fn inference_context(&self) -> &Context<'brand>
Source§fn scribe(ctx: &Context<'brand>, value: &Value) -> Self
fn scribe(ctx: &Context<'brand>, value: &Value) -> Self
value. Read moreSource§fn bit_false(inference_context: &Context<'brand>) -> Self
fn bit_false(inference_context: &Context<'brand>) -> Self
0 as constant output. Read moreSource§fn bit_true(inference_context: &Context<'brand>) -> Self
fn bit_true(inference_context: &Context<'brand>) -> Self
1 as constant output. Read moreSource§fn cond(left: &Self, right: &Self) -> Result<Self, Error>
fn cond(left: &Self, right: &Self) -> Result<Self, Error>
left child is evaluated on the input if the bit is 1 (if branch)
and the right child is evaluated on the input otherwise (else branch). Read moreSource§fn assert(child: &Self, hash: Cmr) -> Result<Self, Error>
fn assert(child: &Self, hash: Cmr) -> Result<Self, Error>
true, and fails otherwise.
The hash identifies the assertion and is returned upon failure. Read moreSource§fn not(child: &Self) -> Result<Self, Error>
fn not(child: &Self) -> Result<Self, Error>
child. Read more