File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 11/// Nat
22
33dec Nat.Add : [Nat, Nat] Nat
4+ dec Nat.Sub : [Nat, Int] Nat
45dec Nat.Mul : [Nat, Nat] Nat
56dec Nat.Div : [Nat, Nat] Nat
67dec Nat.Mod : [Nat, Nat] Nat
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ pub fn external_module() -> Module<Arc<process::Expression<()>>> {
2222 Type :: function( Type :: nat( ) , Type :: function( Type :: nat( ) , Type :: nat( ) ) ) ,
2323 |handle| Box :: pin( nat_add( handle) ) ,
2424 ) ,
25+ Definition :: external(
26+ "Sub" ,
27+ Type :: function( Type :: nat( ) , Type :: function( Type :: int( ) , Type :: nat( ) ) ) ,
28+ |handle| Box :: pin( nat_sub( handle) ) ,
29+ ) ,
2530 Definition :: external(
2631 "Mul" ,
2732 Type :: function( Type :: nat( ) , Type :: function( Type :: nat( ) , Type :: nat( ) ) ) ,
@@ -136,6 +141,12 @@ async fn nat_add(mut handle: Handle) {
136141 handle. provide_nat ( x + y) ;
137142}
138143
144+ async fn nat_sub ( mut handle : Handle ) {
145+ let x = handle. receive ( ) . nat ( ) . await ;
146+ let y = handle. receive ( ) . int ( ) . await ;
147+ handle. provide_nat ( ( x - y) . max ( 0 . into ( ) ) ) ;
148+ }
149+
139150async fn nat_mul ( mut handle : Handle ) {
140151 let x = handle. receive ( ) . nat ( ) . await ;
141152 let y = handle. receive ( ) . nat ( ) . await ;
You can’t perform that action at this time.
0 commit comments