Questions about sharing

Adrian Hey ahey@iee.org
Fri, 7 Dec 2001 14:07:15 +0000


Hello,

I sometimes wonder just how far I should go in obfuscating code by
manually implementing trivial optimisations that should (IMHO) be
implemented by the compiler, but may not be.

So I have a couple of specific questions..

The first is..
Does the compiler keep a unique copy of expressions which consist of just
a single zero arity constructor (eg. [],True,Nothing..) as a CAF which is
referenced each time the constructor appears in an expression, or does it
duplicate the constructor (expression) each time it's used.
Maybe I should define my own CAF at the top level and use it instead?
(or perhaps they're unboxed somehow?)

The second is..
If, following pattern matching, the matched pattern appears in an
expression, is it shared or duplicated..
e.g. (a:as) -> f (a:as)
Maybe I should write something like this..
     x@(a:as) -> f x
(I know that sometimes the type checker won't allow you to do this)

Thanks
-- 
Adrian Hey