Re: [pure-lang-users] Swapping Symbols and Integers
Status: Beta
Brought to you by:
agraef
From: David B. <dh...@gm...> - 2008-08-09 06:28:49
|
On Fri, Aug 8, 2008 at 3:30 AM, Albert Graef <Dr....@t-...> wrote: > So something like this should do the job in Pure: > > a*b::int = b*a if varp a; > x*a*b::int = x*b*a if varp a; > > (In addition, you'll probably need some associativity rules to make this > work in the general case.) Excellent, thanks! I finally got your suggestion to work in Pure. (Took awhile because I had to work around having multiple versions of LLVM installed though so that pure-0.4 would build). I also got it to work in Q: A * B:Int = B * A if isvar A; X * A * B:Int = X * B * A if isvar A; A * (B * C) = A * B * C; Then, I can ask it to reduce an expression like: ==> 3 * ((A * 2) * 4) and I get: 24*A -David |