Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created May 13, 2015 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/94c1a87df7df57f05a94 to your computer and use it in GitHub Desktop.
Save shigemk2/94c1a87df7df57f05a94 to your computer and use it in GitHub Desktop.
import System.IO
import System.Directory
import Data.List
main = do
contents <- readFile "todo.txt"
let todoTasks = lines contents
numberedTasks = zipWith (\n line -> show n ++ " - " ++ line)
[0..] todoTasks
putStrLn "These 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
(tempName, tempHandle) <- openTempFile "." "temp"
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