Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created February 27, 2015 10:19
Show Gist options
  • Save MiyamonY/bf670c1368ef3c9c007b to your computer and use it in GitHub Desktop.
Save MiyamonY/bf670c1368ef3c9c007b to your computer and use it in GitHub Desktop.
import System.IO
import System.Directory
import Data.List
import Control.Exception
main :: IO ()
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
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