hashes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import System.Environment     
import Control.Monad
import Data.Char

import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.HashTable.IO as H

type HashTable k v = H.CuckooHashTable k v

makedict :: IO (HashTable L.ByteString ())
makedict = do
  f  <- L.readFile "/usr/share/dict/words"
  H.fromList (map (flip (,) () . L.map toLower) $ L.lines f)
  

main = do
    [s]  <- getArgs
    dict <- makedict
    g    <- L.readFile s
    mapM_ (spell dict) (L.words g)
        
clean' :: L.ByteString -> L.ByteString
clean' = L.map toLower . L.filter (\x -> isAlpha x || (x == '\'') )


spell d w = do res <- H.lookup d (clean' w)
               case res of
                 Just _  -> return ()
                 Nothing -> L.putStrLn w