Skip to content

Commit

Permalink
feat: add lookupFromReferenceChecked method (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik authored Nov 5, 2024
1 parent 94af3f3 commit a9c1937
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Anoma/Resource/BindingReference.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ trait
type BindingReference DataType RefType :=
mkBindingReference@{
--- Computes the binding reference (RefType) from the data (DataType).
compute : DataType -> RefType;
compute : (data : DataType) -> RefType;
--- Checks whether a particular piece of data matches a binding reference.
check : RefType -> DataType -> Bool;
check : (reference : RefType) -> (data : DataType) -> Bool;
};

--- Implements the ;BindingReference; trait for ;Label;.
Expand All @@ -50,15 +50,27 @@ Value-BindingReference : BindingReference Value ValueRef :=
check := MISSING_JUVIX_IMPLEMENTATION;
};

RefNotFoundError : {A : Type} → A :=
failwith "The referenced data could not be found.";

RefDataMismatchError : {A : Type} → A :=
failwith "The fetched data does not match the referenced data.";

lookupFromRefernce
lookupFromReference
{DataType}
{RefType}
{{BindingReference DataType RefType}}
(bindingRef : RefType)
(reference : RefType)
: Maybe DataType := MISSING_JUVIX_IMPLEMENTATION;

lookupFromReferenceChecked
{DataType}
{RefType}
{{BindingReference DataType RefType}}
(reference : RefType)
: DataType :=
case
lookupFromReference@{
reference;
}
of
| nothing := failwith "The referenced data could not be found."
| just data :=
if
| BindingReference.check reference data := data
| else :=
failwith "The fetched data does not match the referenced data.";

0 comments on commit a9c1937

Please sign in to comment.