32 lines
1.2 KiB
Haskell
32 lines
1.2 KiB
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 =
|
|
let
|
|
parts = words input
|
|
in
|
|
case parts of
|
|
(status : nameParts) ->
|
|
let
|
|
name = unwords nameParts -- Join the remaining parts as the name
|
|
done = case status of
|
|
"x" -> True
|
|
"o" -> False
|
|
_ -> error "Invalid status"
|
|
in
|
|
[(TodoListItem name done, "")]
|
|
_ -> []
|