Lesson learned from Euler Problem 104
Solutions
There are two solutions below. One is written by me and another from haskell wiki.
They look quite similar and I can not figure out why the wiki solution can solve problem but not mine. (Actually mine take more than 15 minutes)
 My Solution
1 2 3 4 5 6 7 8 9 10 11 12 

 Haskell Wiki solution^{1}
1 2 3 4 5 6 7 8 9 10 11 

Why the differences?
The key point here is should test start nine digits first or test end nine digits.
Two concerns here:
show
function is (relatively) slow which used in test first 9 digits function. quite few numbers are end in digits 1..9 in the first 329000 numbers
Therefore test last 9 digits first make great performance improvement.
Thanks Brent^{2} explanation this sneaky thing very comprehensively in haskellbeginner.
Profiling
What help to identify is the GHC profiling tool.
Several options used here are
prof: for basic time and allocation profiling
autoall: auto insert cost centers on all top level functions. “cost center” is a location in the program like to collect statistics about and GHC will generate code to compute the cost of evalutating the expression at each location. e.g.
mean s = {# SCC "mean" #} sum s / fromIntegral (length s)
cafall: function with no parameters only computed once. CAF means constant applicative forms which used for calculate that once time evaluation.
fforcerecomp: force full recompilation.
More details could go to chapter 25^{3} of [Real World Haskell] and GHC user guider chapter 5^{4}.
# build with prof option on
ghc make O2 prof autoall rtsopts p104.hs
# then run
./p104 +RTS p RTS
Further
 Chapter 25 in Real Work Haskell about profile