Artifact Content
Not logged in

Artifact 6a40040679ba714c9849a7da3b21b78c375448cf


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

def binop(a,b,c) {
  fun(x,y){@value(
    if( _isbot( @type(x) ) || _isbot( @type(y) ) ) then @type(...) 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( _isbot(a) ): ( if( _isbot(b) ):"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)) );