todo/app/TodoListItem.hs
2025-05-19 15:42:48 +02:00

29 lines
976 B
Haskell

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)]