Differences From Artifact [12b974146da19906]:
- File
sample/type.pmy
- 2010-11-24 17:44:58 - part of checkin [b993a8ad16] on branch trunk - auto memo and re-run feature of non @value/@macro layers re-re-re-implemented. (user: kinaba) [annotate]
To Artifact [6a40040679ba714c]:
- File
sample/type.pmy
- 2010-11-27 14:23:54 - part of checkin [005474ba5b] on branch trunk - changed: not to lift _|_ (user: kinaba) [annotate]
1 1 @@type = fun(x){
2 2 if _isint(x): "int"
3 3 else if _isstr(x): "str"
4 - else if _isundefined(x): "undefined"
5 4 else: "any"
6 5 };
7 6
8 7 def binop(a,b,c) {
9 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 10 if( @type(x)==a && @type(y)==b ) then c else "error"
12 11 )}
13 12 };
14 13
15 14 @type "+" = binop("int", "int", "int");
16 15 @type "-" = binop("int", "int", "int");
17 16 @type "<" = binop("int", "int", "int");
18 17 @type ">" = binop("int", "int", "int");
19 18
20 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 23 @type "if" = fun(c,t,e) {@value(
25 24 if(@type(c)=="int" ): mergeType(@type(t()), @type(e())) else : "error"
26 25 )};
27 26
28 27 def fib(x)
29 28 {
30 29 if x<2 then 1 else fib(x-1) + fib(x-2)
31 30 };
32 31
33 32 print( @type(fib(10)) );