18 Oct
2008
18 Oct
'08
1:12 p.m.
H mm.. The totals in "sum" and "count" are not computed until printed. This is too lazy. You start with '0' and (+) things to it, but never examine or force the value, so man many (+) thunks are built up in memory. If you use bang patterns then the change can be made here, to !sum !count:
check_line line !sum !count = let match = matchRegex regexp line in case match of Just strs -> (sum + read (head strs) :: Integer, count + 1) Nothing -> (sum, count)
This will force evaluation before every check_line call.