Artifact Content
Not logged in

Artifact 6a40040679ba714c9849a7da3b21b78c375448cf


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