And here's the cool one: var r = a * c * c * c + b * c * c + d * c + e;
reduces to (actual generated code): PTF r = ((PTF a * PTF c + PTF b ) * PTF c + PTF d ) * PTF c + PTF e ; Seems we need 'dependent typing' or something to do this one tho: var r = a * c ^ 3 + + b * c ^ 2 + d * c + e; Specifically can do this: reduce EXP(x:t): x ^ 2 => x * x; reduce EXP(x:t): x ^ 3 => x * x ^ 2; reduce EXP(x:t): x ^ 4 => x * x ^ 3; but we have to write the reductions out for each constant. Enforced constant folding would allow an inductive definition *** to work .. but it would also be applied to terms where the exponent wasn't a constant. *** you'd have to write: reduce EXP(x:t,n:int): x ^ n => if n > 0 then x * x ^ (n - 1) else x endif ; and have the conditional evaluated at compile time. To do this, n would really be a TYPE not an integer. Interesting Felix typematch can actually reduce the conditional right now .. but here we need a type match which returns an executable expression, not a type, and there is currently no such construction. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Felix-language mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/felix-language
