small edit to article

This commit is contained in:
Tony Hannan 2011-07-18 16:33:12 -04:00
parent 82a846e918
commit a1ed175bc2

View file

@ -54,7 +54,7 @@ Stepping through the execution on a small list shows an unevaluated expression b
=> 3 + 3 => 3 + 3
=> 6 => 6
This is not good and unexpected. How can you detect these problems without analyzing every expression for unevaluated expression build up? The answer is: [profile](http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/profiling.html) your application if it is not performing as expected. It will tell you how much time and space different functions are consuming. Once you find the troublesome code, the solution is easy: Force the evaluation of the unevaluated expression by marking it as *strict* (*eager*). This is done by prefixing its variable with `!` and adding language extension [*BangPatterns*](http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/bang-patterns.html). This is not good and unexpected. Fortunately, many of these problems may be recognized by the compiler's [strictness analyzer](http://www.haskell.org/haskellwiki/GHC_optimisations#Strictness_analysis) and fixed automatically. However, it is not guaranteed. So how can you detect these problems without analyzing every expression for unevaluated expression build up? The answer is: [profile](http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/profiling.html) your application if it is not performing as expected. It will tell you how much time and space different functions are consuming. Once you find the troublesome code, the solution is easy: Force the evaluation of the unevaluated expression by marking it as *strict* (*eager*). This is done by prefixing its variable with `!` and adding language extension [*BangPatterns*](http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/bang-patterns.html).
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BangPatterns #-}
reduce op id list = red id list where red !acc list = case list of [] -> acc; head:tail -> red (head `op` acc) tail reduce op id list = red id list where red !acc list = case list of [] -> acc; head:tail -> red (head `op` acc) tail