1: #line 182 "./lpsrc/flx_tut_bind.pak" 2: #import <flx.flxh> 3: struct gauss = { 4: x : int; 5: y : int; 6: } 7: 8: proc _set ( lhs: &gauss, rhs: gauss ) 9: { 10: (*lhs).x = rhs.x; 11: (*lhs).y = rhs.y; 12: } 13: 14: fun add (a:gauss, b:gauss): gauss = { 15: return gauss(a.x+b.x, a.y+b.y); 16: } 17: 18: fun mul (a:gauss, b:gauss): gauss = { 19: return gauss(a.x+b.x - a.y+b.y, a.x*b.y + a.y*b.x); 20: } 21: 22: fun mkgauss (a:int,b:int):gauss = { return gauss(a,b); } 23: fun real (z:gauss):int = { return z.x; } 24: fun imag (z:gauss):int = { return z.y; } 25: 26: proc gprint(z:gauss) { 27: print "("; 28: print (real z); 29: print ", "; 30: print (imag z); 31: print ")"; 32: } 33: 34: fun sqr(z:gauss):gauss = { 35: return z * z; 36: } 37: 38: fun norm(z:gauss): int = { 39: return 40: real z * real z + imag z * imag z 41: ; 42: } 43: 44: val z1 = mkgauss(1,2); 45: val z2 = z1 + z1; 46: val z3 = sqr z2; 47: val n = norm z3; 48: gprint z1; endl; 49: gprint z2; endl; 50: gprint z3; endl; 51: print n; endl;
1: (1, 2) 2: (2, 4) 3: (4, 16) 4: 272
As you can guess, the whole of the program could have been written in C++ rather than Felix.
It's up to you to choose what parts of your Felix program are written directly in C++, and which parts are written in Felix: since Felix is a C++ code generator, it all ends up as C++ anyhow.
Usually, you'll write Felix, except when you have an existing code base containing useful types you need to work with.