Created
June 18, 2014 02:38
-
-
Save mwotton/9b7f3e62f7557343dc1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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