1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/examples/Example3.mjuvix
2021-12-26 17:12:39 -05:00

33 lines
674 B
Plaintext

-- Based on example3.ju in anoma/juvix
module Example3;
import Prelude;
record Account {
balance : Nat;
name : String;
};
record Transaction {
sender : Account;
receiver : Account;
};
record Storage { trans : Transaction; };
determine-maximum-withdraw : String -> Nat;
determine-maximum-withdraw s :=
if s === "bob" then 30
else if s === "maria" then 50
else 0;
accept-withdraws-from : Storage -> Storage -> Bool;
accept-withdraws-from initial final :=
let { withdrawl-amount :=
determine-maximum-withdraw initial.trans.receiver.name;
} in
withdrawl-amount >= final.trans.sender.balance - initial.trans.sender.balance;
end Example3;