view :: [String] -> IO () view [fileName] = do-- match the filename contents <- readFile fileName -- read the file let todoTasks = lines contents -- get the contents numberedTasks = zipWith (\n line -> show n ++ ": " ++ line) [0..] todoTasks putStrLn $ unlines numberedTasks -- show the items
remove :: [String] -> IO () remove [fileName, numberString] = do-- get the filename and the line number handle <- openFile fileName ReadMode (tempName, tempHandle) <- openTempFile ".""temp"-- create a temp file contents <- hGetContents handle -- get contents from the handle let number = read numberString -- read the String to Number todoTasks = lines contents newTodoTasks = delete (todoTasks !! number) todoTasks -- remove the line of the number hPutStr tempHandle $ unlines newTodoTasks -- putStr into the tempfile hClose handle -- close handles hClose tempHandle removeFile fileName renameFile tempName fileName