Use of cpp
ahey at iee.org
Wed Jul 14 08:51:55 EDT 2004
On Tuesday 13 Jul 2004 2:24 pm, Ross Paterson wrote:
> Using any equivalent of #ifdef makes your code hard to maintain: you're
> not compiling all of it at any given time. Sometimes it's unavoidable,
> but for unboxing there is often a portable alternative:
> - to get fields unboxed, add strictness annotations to them and use the
> UNPACK pragma.
> - to get return values unboxed (i.e. components -- you can't unbox
> the whole thing), define a data type with strict fields (as above)
> and return that.
> - to get arguments unboxed, add the minimum number of seq's to make GHC
> believe that the function is strict in those arguments. Unfortunately
> this involves learning to read Core (or at least interface files),
> but after a while you'll get a feel for strictness. A more serious
> problem is that this doesn't work well with higher-order functions.
Yes, I've been relying on tricks like this and compiler optimisation
up to now, but I've decided a more direct approach is called for,
albeit at the expense of using cpp. Squinting at core to find out if
the compiler has optimised code the way you want (and trying to figure
out what to do about it if not) gets a bit tiresome after a while :-)
More information about the Libraries