[Haskell-beginners] Function definition order and performance

Aleksandar Dimitrov aleks.dimitrov at googlemail.com
Mon Jun 6 22:28:25 CEST 2011


Hi,

> If the matching proceeds from top to bottom, will the same functions defined
> in different order have different performance strictly? Thanks.

You should only see a performance difference at all in the case of very
complicated (run-time-wise) guards on pattern matches.

Usually, your pattern matches will have to be placed in a certain order for
*semantic* purposes (i.e. for them to not be overlapping.)

I could imagine a scenario in which a complicated guard on a pattern match,
which could be otherwise rearranged without changing its semantics, on a
function that is itself in the oft-executed loop of an inner function of an
algorithm with high complexity *could* have a noticeable impact on performance.

In other words, premature optimization is the root of all evil.

Are you concerned about a particular case? Example code could help us determine
the reason for slowness.

Regards,
Aleks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110606/dbd324f5/attachment.pgp>


More information about the Beginners mailing list