Skip to content

Instantly share code, notes, and snippets.

@davidsantiago
Created November 23, 2012 20:08
Show Gist options
  • Save davidsantiago/4137077 to your computer and use it in GitHub Desktop.
Save davidsantiago/4137077 to your computer and use it in GitHub Desktop.
import Data.ByteString.Lazy as BSL
import Data.ByteString.Lazy.Char8 as BSC
import Data.Set as Set
tlds :: Set ByteString
tlds = Set.map BSC.pack $ Set.fromList ["biz", "bz", "cc",
"co", "com", "es", "info",
"io", "me", "net", "org",
"pro", "tv", "us", "ws"]
dropPrefix prefix word = BSC.drop (BSC.length prefix) word
coword prefix word = append (dropPrefix prefix word)
prefix
coWords dict word =
let prefixes = Set.filter (`isPrefixOf` word) tlds
in
Set.filter (\pre -> (member (dropPrefix pre word) dict)
|| (member (coword pre word) dict))
prefixes
main = do file <- BSL.readFile "/usr/share/dict/words"
let dict = Set.fromList $ BSC.words file
let wordsWithCowords = Set.filter (\x -> (coWords dict x) /= Set.empty) dict
print $ Set.map BSC.unpack wordsWithCowords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment