Diff
Not logged in

Differences From Artifact [12b974146da19906]:

To Artifact [6a40040679ba714c]:


1 @@type = fun(x){ 1 @@type = fun(x){ 2 if _isint(x): "int" 2 if _isint(x): "int" 3 else if _isstr(x): "str" 3 else if _isstr(x): "str" 4 else if _isundefined(x): "undefined" < 5 else: "any" 4 else: "any" 6 }; 5 }; 7 6 8 def binop(a,b,c) { 7 def binop(a,b,c) { 9 fun(x,y){@value( 8 fun(x,y){@value( 10 if( @type(x)=="undefined" || @type(y)=="undefined" ) then "undefined" else | 9 if( _isbot( @type(x) ) || _isbot( @type(y) ) ) then @type(...) else 11 if( @type(x)==a && @type(y)==b ) then c else "error" 10 if( @type(x)==a && @type(y)==b ) then c else "error" 12 )} 11 )} 13 }; 12 }; 14 13 15 @type "+" = binop("int", "int", "int"); 14 @type "+" = binop("int", "int", "int"); 16 @type "-" = binop("int", "int", "int"); 15 @type "-" = binop("int", "int", "int"); 17 @type "<" = binop("int", "int", "int"); 16 @type "<" = binop("int", "int", "int"); 18 @type ">" = binop("int", "int", "int"); 17 @type ">" = binop("int", "int", "int"); 19 18 20 def mergeType(a,b) { 19 def mergeType(a,b) { 21 if( a == "undefined" ): ( if(b=="undefined"):"error" else b ) else ( a ) | 20 if( _isbot(a) ): ( if( _isbot(b) ):"error" else b ) else ( a ) 22 }; 21 }; 23 22 24 @type "if" = fun(c,t,e) {@value( 23 @type "if" = fun(c,t,e) {@value( 25 if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error" 24 if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error" 26 )}; 25 )}; 27 26 28 def fib(x) 27 def fib(x) 29 { 28 { 30 if x<2 then 1 else fib(x-1) + fib(x-2) 29 if x<2 then 1 else fib(x-1) + fib(x-2) 31 }; 30 }; 32 31 33 print( @type(fib(10)) ); 32 print( @type(fib(10)) );