Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created June 18, 2014 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwotton/9b7f3e62f7557343dc1c to your computer and use it in GitHub Desktop.
Save mwotton/9b7f3e62f7557343dc1c to your computer and use it in GitHub Desktop.
module Completions where
import Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS
import Data.Trie
buildTrie :: FilePath -> IO (ByteString -> [ByteString])
buildTrie fp = do
t <- fromList . map (\x -> (x,())) . BS.lines <$> BS.readFile fp
return (\n -> keys $ submap n t)
orb ➜ ~/projects/trie cabal repl sandboxed
Preprocessing library trie-0.1.0.0...
GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package bytestring-0.10.4.0 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package binary-0.7.1.0 ... linking ... done.
Loading package bytestring-trie-0.2.3 ... linking ... done.
[1 of 1] Compiling Completions ( Completions.hs, interpreted )
Ok, modules loaded: Completions.
*Completions> f <- buildTrie "./wlist_match10.txt"
*Completions> :set -XOverloadedStrings
*Completions> f "elep"
["elephant","elephants"]
*Completions> f "hand"
["hand","handbook","handbooks","handcuffs","handed","handedly","handel","handful","handgun","handguns","handicap","handiwork","handkerchief","handle","handlebar","handlebars","handled","handler","handlers","handles","handling","handmade","handout","handouts","hands","handset","handshake","handsome","handwriting","handwritten","handy"]
*Completions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment