module TodoListItem where data TodoListItem = TodoListItem { name :: String , done :: Bool } deriving (Eq) instance Show TodoListItem where show (TodoListItem name done) = s done ++ " " ++ name ++ "\n" where s True = "x" s False = "o" showList = foldr ((.) . shows) id instance Read TodoListItem where readsPrec _ input = do let (item, rest) = break (== '\n') input let (d, n) = splitAt 2 item let done = case d of "x " -> True "o " -> False _ -> error "Invalid status" name = case n of "" -> error "empty name" something -> filter (/= '\r') something [(TodoListItem name done, rest)]