What Haskell icons can I use to implement real-time autocomplete on the command line?

I am trying to get an idea of ​​the basics of Haskell by creating a Notational Velocity-style search style search on the command line. Instead of solving the whole problem, I try its very basic version: There is a file with 10 lines and a 3-letter word on each line. After each letter that I type, I want to update the display of the list of line numbers, which may contain the word that I am typing, based on my input.

Can someone demonstrate a Haskell program that does this? I think my problem is that you are reevaluating for each character input. Thank you a million in advance.

+8
command-line shell haskell
source share
2 answers

I will not try to write the entire Haskell program that you are asking for, but here is a very short example showing only the bit that you claim to be stuck at the moment: do something after each keystroke. We won’t do anything interesting (just jot down a number and print it out), but it will show how to complete this small task, and you can probably start hacking from there.

The only thing you really need to know is that you don't seem to be able to disable input line buffering.

import System.IO loop n = do c <- getChar print n -- do whatever recalculation you need to do here, using -- n (which can be more complicated than an Integer, as -- it is here, of course) and c (which is a Char -- representing the key the user whacked) -- our recalculation is just to increase n by one loop (n+1) main = do hSetBuffering stdin NoBuffering -- do this once before anything else loop 0 
+2
source share

Learning about reactive programming can be a good start.
For this, a good library seems like a reactive banana
There is an example base.

If you want to know more about FRP, a great topic on stack will give you a clear overview.

+1
source share

All Articles