shadow123
shadow123

Reputation: 11

Haskeline word completion with list

Haskell newbie here and also first time asking a question here, apologies in advance for anything I may have missed anything.

Im writing a repl function that takes user input, adds the input to a list and uses haskeline to tab complete user input with previously typed words.

So far I can only complete words with a static list defined before run time.

1- How would I add the input word to the list in repl (SOLVED...?)

2- How would I enable the searchFunc to query the list in the repl loop?

My current code:

import Data.List
import System.Console.Haskeline

-- main method
main :: IO ()
main = runInputT mySettings (repl [])

repl :: [String] -> InputT IO ()
repl list =
    do
        minput <- getInputLine "> "
        case minput of
            Nothing     ->  do
                            outputStrLn "Error"
                            repl list

            Just input  ->
                           do
                           outputStrLn "Successfully added input to list"
                           -- < 1- add input word to list ... is this correct?>
                           repl (input:list)

mySettings :: Settings IO
mySettings = Settings { historyFile = Just "myhist",
                        complete = completeWord Nothing " \t" $ return . searchFunc,
                        autoAddHistory = True
                      }


searchFunc :: String -> [Completion]
-- < 2- complete word using list of words from repl>
searchFunc str = map simpleCompletion $ filter (str `isPrefixOf`) listFromRepl

Any help is appreciated, thanks in advance.

Upvotes: 1

Views: 159

Answers (0)

Related Questions