From: Albert G. <Dr....@t-...> - 2008-08-24 21:31:23
|
David Baird wrote: > I have a quite Pure (0.4) question. This is what I want, but in > prefix-form not infix-form: > > > -1*A; > -1*A I don't understand. Do you want "1 multiplied by A negated" or "1 negated, multiplied by A"? -(1*A) will give you the former, (-1)*A the latter (in either Pure or Q). Or you can write it with an explicit application of the unary minus operator, which is available as the 'neg' function in Pure ('minus' in Q): > neg (1*A); -1*A > (neg 1)*A; (-1)*A Note that in Pure unary minus always has the same precedence as binary minus, whereas in Q unary minus has higher precedence than all the infix operators. Therefore, -1*A is actually -(1*A) in Pure, whereas it denotes (-1)*A in Q. Usually this difference doesn't really matter, but of course here it does. The rationale behind Pure's syntax is that unary minus has the right precedence no matter what the precedence of binary minus (which you can change freely in the prelude) happens to be. Also, it's compatible with mathematical notation, Haskell, Pascal and a bunch of other languages (not C though, C has the unary operators at a higher precedence level, like Q does). HTH, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |