Data.GADT.Show

some-1.0.6: Existential type: Some

Safe Haskell | Safe
Language | Haskell2010

Data.GADT.Show

Contents

- Showing
- Reading

Synopsis

- class GShow (t :: k -> Type) where
  - gshowsPrec :: forall (a :: k). Int -> t a -> ShowS
- defaultGshowsPrec :: forall {k} t (a :: k). Show (t a) => Int -> t a -> ShowS
- gshows :: forall {k} t (a :: k). GShow t => t a -> ShowS
- gshow :: forall {k} t (a :: k). GShow t => t a -> String
- class GRead (t :: k -> Type) where
  - greadsPrec :: Int -> GReadS t
- type GReadS (t :: k -> Type) = String -> [(Some t, String)]
- greads :: forall {k} (t :: k -> Type). GRead t => GReadS t
- gread :: GRead t => String -> (forall (a :: k). t a -> b) -> b
- greadMaybe :: GRead t => String -> (forall (a :: k). t a -> b) -> Maybe b
- getGReadResult :: Some tag -> (forall (a :: k). tag a -> b) -> b
- mkGReadResult :: forall {k} tag (a :: k). tag a -> Some tag

# Showing

class GShow (t :: k -> Type) where #

`Show`-like class for 1-type-parameter GADTs. `GShow t => ...` is equivalent to something like `(forall a. Show (t a)) => ...`. The easiest way to create instances would probably be to write (or derive) an `instance Show (T a)`, and then simply say:

    instance GShow t where gshowsPrec = defaultGshowsPrec

Methods

gshowsPrec :: forall (a :: k). Int -> t a -> ShowS #

#### Instances

Instances details

GShow SNat # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a :: Nat). Int -> SNat a -> ShowS #
GShow SChar # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a :: Char). Int -> SChar a -> ShowS #
GShow SSymbol # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a :: Symbol). Int -> SSymbol a -> ShowS #
GShow (TypeRep :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a :: k). Int -> TypeRep a -> ShowS #
GShow ((:~:) a :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :~: a0) -> ShowS #
GShow (GOrdering a :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> GOrdering a a0 -> ShowS #
(GShow a, GShow b) => GShow (Product a b :: k -> Type) # |
    >>> gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)
    "Pair Refl Refl"
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> Product a b a0 -> ShowS #
(GShow a, GShow b) => GShow (Sum a b :: k -> Type) # |
    >>> gshow (InL Refl :: Sum ((:~:) Int) ((:~:) Bool) Int)
    "InL Refl"
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> Sum a b a0 -> ShowS #
GShow ((:~~:) a :: k -> Type) # | Since: 1.0.4
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :~~: a0) -> ShowS #
(GShow a, GShow b) => GShow (a :*: b :: k -> Type) # |
    >>> gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)
    "Refl :*: Refl"
Since: 1.0.4
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :*: b) a0 -> ShowS #
(GShow a, GShow b) => GShow (a :+: b :: k -> Type) # |
    >>> gshow (L1 Refl :: ((:~:) Int :+: (:~:) Bool) Int)
    "L1 Refl"
Since: 1.0.4
Instance details Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :+: b) a0 -> ShowS #

defaultGshowsPrec :: forall {k} t (a :: k). Show (t a) => Int -> t a -> ShowS #

If `f` has a 'Show (f a)' instance, this function makes a suitable default implementation of `gshowsPrec`.

Since: 1.0.4

gshows :: forall {k} t (a :: k). GShow t => t a -> ShowS #

gshow :: forall {k} t (a :: k). GShow t => t a -> String #

# Reading

class GRead (t :: k -> Type) where #

`Read`-like class for 1-type-parameter GADTs. Unlike `GShow`, this one cannot be mechanically derived from a `Read` instance because `greadsPrec` must choose the phantom type based on the `String` being parsed.

Methods

greadsPrec :: Int -> GReadS t #

#### Instances

Instances details

GRead ((:~:) a :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS ((:~:) a) #
GRead (GOrdering a :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS (GOrdering a) #
(GRead a, GRead b) => GRead (Sum a b :: k -> Type) # |
Instance details Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS (Sum a b) #
(GRead a, GRead b) => GRead (a :+: b :: k -> Type) # | Since: 1.0.4
Instance details Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS (a :+: b) #
k1 ~ k2 => GRead ((:~~:) a :: k2 -> Type) # | Since: 1.0.4
Instance details Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS ((:~~:) a :: k2 -> Type) #

type GReadS (t :: k -> Type) = String -> [(Some t, String)] #

`GReadS t` is equivalent to `ReadS (forall b. (forall a. t a -> b) -> b)`, which is in turn equivalent to `ReadS (Exists t)` (with `data Exists t where Exists :: t a -> Exists t`)

greads :: forall {k} (t :: k -> Type). GRead t => GReadS t #

gread :: GRead t => String -> (forall (a :: k). t a -> b) -> b #

greadMaybe :: GRead t => String -> (forall (a :: k). t a -> b) -> Maybe b #

    >>> greadMaybe "InL Refl" mkSome :: Maybe (Some (Sum ((:~:) Int) ((:~:) Bool)))
    Just (mkSome (InL Refl))

    >>> greadMaybe "L1 Refl" mkSome :: Maybe (Some ((:~:) Int :+: (:~:) Bool))
    Just (mkSome (L1 Refl))

    >>> greadMaybe "garbage" mkSome :: Maybe (Some ((:~:) Int))
    Nothing

getGReadResult :: Some tag -> (forall (a :: k). tag a -> b) -> b #

mkGReadResult :: forall {k} tag (a :: k). tag a -> Some tag #