import Data Char toUpper type Todo String type TodoList Todo numberLis

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Data.Char (toUpper)
type Todo = String
type TodoList = [Todo]
numberList :: TodoList -> [String]
numberList = zipWith (\a b -> show a ++ ". " ++ b) [1..]
removeElem :: Int -> [a] -> [a]
removeElem i xs = let (as, bs) = splitAt i xs
in as ++ drop 1 bs
printStrs :: [String] -> IO ()
printStrs = mapM_ putStrLn
showTodoList :: TodoList -> String
showTodoList [] = "No entries"
showTodoList xs = unlines xs
addTodo :: TodoList -> Todo -> TodoList
addTodo = flip (:)
removeTodo :: TodoList -> Int -> TodoList
removeTodo = flip removeElem
prompt :: String -> IO String
prompt xs = putStrLn xs >> getLine
todoOp :: TodoList -> Char -> IO TodoList
todoOp xs 'V' = printStrs xs >> return xs
todoOp xs 'A' = addTodo xs <$> prompt "What would you like to add?"
todoOp [] 'D' = putStrLn (showTodoList []) >> return []
todoOp xs 'D' = printStrs xs >> removeTodo xs <$> prompt "Which line do you want to remove? " --> ERROR
todoOp xs _ = putStrLn "Operation not supported" >> return xs