Skip to content

missed CSE opportunity

Don't know if this is a bug, but it was at least surprising to find that

playerMostOccur [a] = a
playerMostOccur (x:xs)
 | numOccur x (x:xs) > numOccur (playerMostOccur xs) xs = x
 | otherwise = playerMostOccur xs

was exponentially slower when compiled with ghc-5.04.2 -O than:

playerMostOccur [a] = a
playerMostOccur (x:xs)
 | numOccur x (x:xs) > numOccur pmo xs = x
 | otherwise = pmo
 where pmo = playerMostOccur xs

Although the student responsible for the code couldn't spot the obvious optimisation, I was expecting that GHC's optimiser would. :) If it's not a bug, could you explain it to me?

-Greg(gregm.at.cs.uwa.edu.au)

Edited by Simon Marlow
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information