[mercury-users] maybe(T)

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Oct 21 15:01:14 AEST 2002


On 21-Oct-2002, Michael Day <mikeday at yeslogic.com> wrote:
> 
> My main concern was that using maybe(T) wouldn't introduce
> unnecessary extra pointer manipulation; if it has no space/time overhead
> then no problem :)

Overhead compared to what?

Using `maybe(T)' does have an extra level of indirection compared to using
plain `T' (just as in C, `T *' has an extra level compared to `T').

If you are extremely concerned with efficiency, and you want to
micro-optimize the inner loops of your application, then it may
be more efficient to use a sentinel value of type `T'.  However,
this is definitely not recommended for normal programming, only
for optimizing performance-critical inner loops.  Even then, it
may not be necessary, because in some circumstances the compiler's
deforestation optimization can eliminate intermediate values of
type `maybe(T)'... profile your application carefully before attempting
such low-level optimizations.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list