Artifact Content
Not logged in

Artifact 12b974146da199064d32689e2a25475a2e051659


@@type = fun(x){
  if _isint(x): "int"
  else if _isstr(x): "str" 
  else if _isundefined(x): "undefined"
  else: "any"
};

def binop(a,b,c) {
  fun(x,y){@value(
    if( @type(x)=="undefined" || @type(y)=="undefined" ) then "undefined" else
      if( @type(x)==a && @type(y)==b ) then c else "error"
  )}
};

@type "+" = binop("int", "int", "int");
@type "-" = binop("int", "int", "int");
@type "<" = binop("int", "int", "int");
@type ">" = binop("int", "int", "int");

def mergeType(a,b) {
  if( a == "undefined" ): ( if(b=="undefined"):"error" else b  ) else ( a )
};

@type "if" = fun(c,t,e) {@value(
 if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error"
)};

def fib(x)
{
	if x<2 then 1 else fib(x-1) + fib(x-2)
};

print( @type(fib(10)) );