1: include "std"; 2: 3: fun sign1(x:int):int = 4: { 5: return 6: if x < 0 then -1 7: else 8: if x == 0 then 0 9: else 1 10: endif 11: endif 12: ; 13: } 14: 15: print (sign1 (-20)); endl; 16: print (sign1 0); endl; 17: print (sign1 20); endl; 18: 19: fun sign2(x:int):int = 20: { 21: return 22: if x < 0 then -1 23: elif x == 0 then 0 24: else 1 25: endif 26: ; 27: } 28: 29: print (sign2 (-20)); endl; 30: print (sign2 0); endl; 31: print (sign2 20); endl; 32: 33: 34: fun sign3(x:int):int = 35: { 36: return 37: match x < 0 with 38: | case 2 => -1 // true 39: | case 1 => // false 40: match x == 0 with 41: | case 2 => 0 // true 42: | case 1 => 1 // false 43: endmatch 44: endmatch 45: ; 46: } 47: 48: print (sign3 (-20)); endl; 49: print (sign3 0); endl; 50: print (sign3 20); endl; 51: 52:
The conditional expression is merely a shortcut for a match, as shown in the third sign function.