At the moment, I have this code in and around main
:
import Control.Monad
import Control.Applicative
binSearch :: Ord a => [a] -> a -> Maybe Int
main = do
xs <- lines <$> readFile "Cars1.txt"
x <- getLine <* putStr "Registration: " -- Right?
putStrLn $ case binSearch xs x of
Just n -> "Found at position " ++ show n
Nothing -> "Not found"
My hope is for “Registration: ” to be printed, then for the program to wait for the input to x
. Does what I've written imply that that will be the case? Do I need the <*
, or will putting the putStr
expression on the line above make things work as well?
PS: I know I have to convert binSearch
to work with arrays rather than lists (otherwise it's probably not worth doing a binary search), but that's a problem for another day.