5afe8e3f26 2010-11-13 kinaba: @@type = fun(x){ 3ae09b8cbf 2010-11-24 kinaba: if _isint(x): "int" 3ae09b8cbf 2010-11-24 kinaba: else if _isstr(x): "str" 3ae09b8cbf 2010-11-24 kinaba: else: "any" 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def binop(a,b,c) { f86026acb8 2010-11-21 kinaba: fun(x,y){@value( 005474ba5b 2010-11-27 kinaba: if( _isbot( @type(x) ) || _isbot( @type(y) ) ) then @type(...) else 3ae09b8cbf 2010-11-24 kinaba: if( @type(x)==a && @type(y)==b ) then c else "error" 5afe8e3f26 2010-11-13 kinaba: )} 5afe8e3f26 2010-11-13 kinaba: }; 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: @type "+" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "-" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type "<" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: @type ">" = binop("int", "int", "int"); 5afe8e3f26 2010-11-13 kinaba: 5afe8e3f26 2010-11-13 kinaba: def mergeType(a,b) { 005474ba5b 2010-11-27 kinaba: if( _isbot(a) ): ( if( _isbot(b) ):"error" else b ) else ( a ) f86026acb8 2010-11-21 kinaba: }; f86026acb8 2010-11-21 kinaba: f86026acb8 2010-11-21 kinaba: @type "if" = fun(c,t,e) {@value( 3ae09b8cbf 2010-11-24 kinaba: if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error" f86026acb8 2010-11-21 kinaba: )}; b993a8ad16 2010-11-24 kinaba: b993a8ad16 2010-11-24 kinaba: def fib(x) b993a8ad16 2010-11-24 kinaba: { b993a8ad16 2010-11-24 kinaba: if x<2 then 1 else fib(x-1) + fib(x-2) b993a8ad16 2010-11-24 kinaba: }; b993a8ad16 2010-11-24 kinaba: b993a8ad16 2010-11-24 kinaba: print( @type(fib(10)) );