{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE CPP #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Safe #-}
#endif
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE PolyKinds #-}
#endif
module Data.GADT.Show where
#if MIN_VERSION_base(4,10,0)
import qualified Type.Reflection as TR
#endif
class GShow t where
gshowsPrec :: Int -> t a -> ShowS
#if MIN_VERSION_base(4,10,0)
instance GShow TR.TypeRep where
gshowsPrec = showsPrec
#endif
gshows :: GShow t => t a -> ShowS
gshows = gshowsPrec (-1)
gshow :: (GShow t) => t a -> String
gshow x = gshows x ""
newtype GReadResult t = GReadResult
{ getGReadResult :: forall b . (forall a . t a -> b) -> b }
type GReadS t = String -> [(GReadResult t, String)]
class GRead t where
greadsPrec :: Int -> GReadS t
greads :: GRead t => GReadS t
greads = greadsPrec (-1)
gread :: GRead t => String -> (forall a. t a -> b) -> b
gread s g = case hd [f | (f, "") <- greads s] of
GReadResult res -> res g
where
hd (x:_) = x
hd _ = error "gread: no parse"