Created
November 18, 2019 20:03
-
-
Save Magicloud/e1673f9542138976bc3c1082c81e7fd9 to your computer and use it in GitHub Desktop.
Invertible syntax Read/Show.
This file contains 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
-- Copied from https://www.howtobuildsoftware.com/index.php/how-do/fWl/haskell-template-haskell-deriving-custom-derivingreadshow-for-enum-type | |
import Prelude hiding (Applicative(..), print) | |
import Data.Maybe (fromJust) | |
import Text.Syntax | |
import Text.Syntax.Parser.Naive | |
import Text.Syntax.Printer.Naive | |
data TVShow = BobsBurgers | MrRobot | BatmanTAS deriving (Eq, Ord) | |
tvShow :: Syntax f => f TVShow | |
tvShow = pure BobsBurgers <* text "Bob's Burgers" | |
<|> pure MrRobot <* text "Mr. Robot" | |
<|> pure BatmanTAS <* text "Batman: The Animated Series" | |
runParser (Parser p) = p | |
instance Read TVShow where readsPrec _ = runParser tvShow | |
instance Show TVShow where show = fromJust . print tvShow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment