1: #line 640 "./lpsrc/flx_tutorial.pak" 2: #import <flx.flxh> 3: 4: union parity = 5: | Odd 6: | Even 7: ; 8: 9: union int_option = 10: | iSome of int 11: | iNone 12: ; 13: 14: enum E {zero, one, two}; 15: 16: val x = Odd; 17: val y = iSome 1; 18: val z = one; 19: 20: enum X {a,b=2,c,d=0xf}; 21: fun str : X->string = 22: | a => "a" 23: | b => "b" 24: | c => "c" 25: | d => "d" 26: ; 27: 28: print$ str a + str (caseno a); endl; 29: print$ str b + str (caseno b); endl; 30: print$ str c + str (caseno c); endl; 31: print$ str d + str (caseno d); endl; 32: 33:
In their second role, the constructors are considered functions, so that Some is a function with type:
int -> int_optionIt is important to note that the constructor names are visible in the enclosing space, unlike struct component names.
The enum form only permits constant constructors (ones with no arguments), values are not permitted.