nlpwp/book — Issue #7: 7.2. Frequency-based tagging - force strictness
Author: hmf
Created: 2011-11-02 09:29:58+00:00
State: open

In tokenTagFreqs it may be better to replace M.insertWith (twice) with M.insertWith'
in order to avoid generating thunks (suggested by Daniel Fischer in the Haskell
begginner's list).

``` Haskell
tokenTagFreqs :: [TrainingInstance] -> M.Map Token (M.Map Tag Integer)
tokenTagFreqs = L.foldl' countWord M.empty
where countWord m (TrainingInstance token tag) =
M.insertWith' (countTag tag) token (M.singleton tag 1) m
countTag tag _ old = M.insertWith' (\newFreq oldFreq -> newFreq + oldFreq) tag 1 old
```