Created
November 25, 2017 09:51
-
-
Save mizukmb/adbe41d5a810b6b001e20cb7bb256890 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
import System.IO | |
import System.Directory | |
import Data.List | |
import Control.Exception | |
main = do | |
contents <- readFile "todo.txt" | |
let todoTasks = lines contents | |
numberedTasks = zipWith (\n line -> show n ++ " - " ++ line) [0..] todoTasks | |
putStrLn "There are your TO-DO items:" | |
mapM_ putStrLn numberedTasks | |
putStrLn "Which one do you want to delete?" | |
numberString <- getLine | |
let number = read numberString | |
newTodoItems = unlines $ delete (todoTasks !! number) todoTasks | |
bracketOnError (openTempFile "." "temp") | |
(\(tempName, tempHandle) -> do | |
hClose tempHandle | |
removeFile tempName) | |
(\(tempName, tempHandle) -> do | |
hPutStr tempHandle newTodoItems | |
hClose tempHandle | |
removeFile "todo.txt" | |
renameFile tempName "todo.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment