The replace function from my earlier post appears to work well and it can be used in function composition. The only downside is its speed. If you want to replace seven characters, you have to make seven runs through the list and this takes time with the Brown Corpus – 12 seconds. So I looked for an alternative.

The first alternative was a simple case:

replace' :: [Char] -> [Char]
replace' [] = []
replace' (x:xs) = case x of
		'.' -> " _." ++ replace' xs
		',' -> " _," ++ replace' xs
		';' -> " _;" ++ replace' xs
		'"' -> " _"" ++ replace' xs
		'!' -> " _!" ++ replace' xs
		':' -> " _:" ++ replace' xs
		'?' -> " _?" ++ replace' xs
		_ -> x : replace' xs

It only needs one run and the application was faster: 8 seconds. I also tried the replace function from Data.List.Utils, but it needed 15 seconds. In the end, I stuck with the case function.

I cleaned up brown4.hs a bit, added comments, and that’s that. Next stop: suffix arrays.