Skip to content

Instantly share code, notes, and snippets.

@jacobstanley
Created March 6, 2016 00:40
Show Gist options
  • Save jacobstanley/d9063117e034bbf231bf to your computer and use it in GitHub Desktop.
Save jacobstanley/d9063117e034bbf231bf to your computer and use it in GitHub Desktop.
Showing GADTs
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