2 points on language

D. Tweed [email protected]
Fri, 24 Aug 2001 10:23:36 +0100 (BST)

On Fri, 24 Aug 2001, S.D.Mechveliani wrote:

> D. Tweed <[email protected]> writes
> > On a purely pragmatic note ( :-) ) these optimisations can't necessarily
> > be safely used in three of the four most common cases, namely Int, Float
> > and Double because of the restricted range of intermediates. 
> Int, Float, Double  
> are not supposed to be provided with the  CommutativeRing  instance.
> And most common cases are, to my mind, different:
> Integer, Rational, (Integer, Rational), Polynomial Integer ...

Ah, I must admit I'd rather missed the point that you were only intending
them to apply to things that were of the algebraic class `Commutative
Ring'. I was thinking that it'd be something where a particular funciton
over a (possibly polymorphic) type could be declared associative,
commutative, etc and then those more elementary classes came together in
the particular example of the CommutativeRing. For example, the operator
++ on lists is associative, there are useful computational savings to be
made utilising this (IIRC Lennart Augustsson had this specal cased in the
hbc compiler), but it's difficult to see how you gain anything by trying
to pin down any of the other properties of lists that would figure in the
mathematically standard classes (there's no inverse as far as I can see so
we don't even make it as far as a group). I think from the point of view
of lobbying compiler implementors to put in the spade work to make this
happen you're more likely to get support if the elegant algebraic classes
come as a neat combination of more low-level, `unstructured' features.

Don't get me wrong, I like the idea of extending the power of the Haskell
compilers, I was just pointing out that the obvious thought that
associative- and commutative-rewrite based optimisation `will also be very
helpful for programs that are doing "everyday arithmetic" operations (say
running a Kalman filter over a sequence of data represented using
Doubles)' isn't necessarily true, and it certainly wasn't obvious to me:
it was only happening upon the reference in the MetaFont book that made me
realise it.

www.cs.bris.ac.uk/~tweed/pi.htm |tweed's law:  however many computers
email: [email protected]      |   you have, half your time is spent
work tel: (0117) 954-5250       |   waiting for compilations to finish.