1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00
juvix/examples/Example2.mjuvix
2021-12-26 17:12:39 -05:00

45 lines
931 B
Plaintext

-- Based on example2.ju in anoma/juvix
module Example2;
import Prelude hiding {Bool, True, False};
record Account {
balance : Nat;
name : String;
};
record Transaction {
sender : Account;
receiver : Account;
};
record Storage { trans : Transaction; };
inductive TrustLevel {
Trusted : Nat -> TrustLevel;
NotTrusted : TrustLevel
};
determine-trust-level : String -> TrustLevel;
determine-trust-level s :=
if s === "bob" then (Trusted 30)
else if s === "maria" then (Trusted 50)
else NotTrusted;
inductive Bool {
True : Bool;
False : Bool;
};
accept-withdraws-from : Storage -> Storage -> Bool;
accept-withdraws-from initial final :=
let { trusted? := determine-trust-level initial.trans.receiver.name; }
in match trusted? {
Trusted funds |->
funds.maximum-withdraw >=final.trans.sender.balance - initial.trans.sender.balance;
NotTrusted |-> False;
};
end Example2;