Created
April 16, 2020 10:02
-
-
Save jchia/afa09464d83b46a8849f278e227dbd42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Session = Session { date :: Date, nightDay :: NightDay } deriving (Bounded, Eq, Generic, Ord) | |
instance Show Session where | |
show (Session date Night) = show date `snoc` 'n' | |
show (Session date Day) = show date | |
sessionParser :: (Stream a, Token a ~ Char) => Parsec () a Session | |
sessionParser = do | |
date <- dateParser | |
night <- optional (char 'n') | |
pure $ Session date (bool Day Night $ isJust night) | |
instance Read Session where | |
readPrec = do | |
x <- RP.look | |
case MP.runParser' sessionParser $ MP.State x (singleton $ MP.initialPos "") 0 MP.defaultTabWidth of | |
(_, Left _) -> fail "Bad session" | |
(MP.State _ _ processed _, Right s) -> do replicateM_ processed RP.get | |
pure s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment