Created
March 6, 2016 00:40
-
-
Save jacobstanley/d9063117e034bbf231bf to your computer and use it in GitHub Desktop.
Showing GADTs
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
data Parser a where | |
Val :: Show a => a -> Parser a | |
Cat :: Parser a -> Parser b -> Parser (a, b) | |
instance Show (Parser a) where | |
showsPrec p x = | |
showParen (p > 10) $ | |
case x of | |
Val n -> | |
showString "Val " . | |
showsPrec 11 n | |
Cat a b -> | |
showString "Cat " . | |
showsPrec 11 a . | |
showChar ' ' . | |
showsPrec 11 b | |
data Parser2 a where | |
Val2 :: Int -> Parser2 a | |
Cat2 :: Parser2 a -> Parser2 b -> Parser2 (a, b) | |
instance Show (Parser2 a) where | |
showsPrec p x = | |
showParen (p > 10) $ | |
case x of | |
Val2 n -> | |
showString "Val2 " . | |
showsPrec 11 n | |
Cat2 a b -> | |
showString "Cat2 " . | |
showsPrec 11 a . | |
showChar ' ' . | |
showsPrec 11 b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment