1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-14 17:32:00 +03:00
juvix/examples/Example2.mjuvix

45 lines
931 B
Plaintext
Raw Normal View History

2021-12-27 01:12:39 +03:00
-- 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;
};
2021-12-27 01:12:39 +03:00
end Example2;