Skip to content

Instantly share code, notes, and snippets.

@jchia
Created April 16, 2020 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchia/afa09464d83b46a8849f278e227dbd42 to your computer and use it in GitHub Desktop.
Save jchia/afa09464d83b46a8849f278e227dbd42 to your computer and use it in GitHub Desktop.
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