Word frequency: Difference between revisions

headers
(headers)
Line 2,451:
 
=={{header|Haskell}}==
===Lazy IO with pure Map, arrows===
{{trans|Clojure}}
<lang Haskell>module Main where
Line 2,499 ⟶ 2,500:
</pre>
 
===Lazy IO, map of IORefs===
 
Using IORefs as values in the map seems to give a ~2x speedup on large files. The below code is based on https://github.com/composewell/streamly-examples/blob/master/examples/WordFrequency.hs , but still using lazy IO to avoid the extra library dependency (in production you should [https://stackoverflow.com/questions/5892653/whats-so-bad-about-lazy-i-o use a streaming library] like streamly/conduit/io-streams):
<lang haskell>
Line 2,547 ⟶ 2,548:
</pre>
 
===Lazy IO, short code, but not streaming===
Or, perhaps a little more simply, though not streaming (will read everything into memory, don't use on big files):
<lang haskell>import qualified Data.Text.IO as T
Anonymous user