-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Dependent sum type -- @package dependent-sum @version 0.3.2.0 module Data.GADT.Show -- | 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 = showsPrec --class GShow t gshowsPrec :: GShow t => Int -> t a -> ShowS gshows :: GShow t => t a -> ShowS gshow :: GShow t => t a -> 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) type GReadS t = String -> [(forall b. (forall a. t a -> b) -> b, String)] -- | 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. class GRead t greadsPrec :: GRead t => Int -> GReadS t greads :: GRead t => GReadS t gread :: GRead t => String -> (forall a. t a -> b) -> b module Data.GADT.Compare -- | Backwards compatibility alias; as of GHC 7.8, this is the same as -- `(:~:)`. type (:=) = (:~:) -- | A class for type-contexts which contain enough information to (at -- least in some cases) decide the equality of types occurring within -- them. class GEq f geq :: GEq f => f a -> f b -> Maybe (a := b) -- | If f has a GEq instance, this function makes a -- suitable default implementation of '(==)'. defaultEq :: GEq f => f a -> f b -> Bool -- | If f has a GEq instance, this function makes a -- suitable default implementation of '(/=)'. defaultNeq :: GEq f => f a -> f b -> Bool -- | A type for the result of comparing GADT constructors; the type -- parameters of the GADT values being compared are included so that in -- the case where they are equal their parameter types can be unified. data GOrdering a b GLT :: GOrdering a b GEQ :: GOrdering t t GGT :: GOrdering a b -- | TODO: Think of a better name -- -- This operation forgets the phantom types of a GOrdering value. weakenOrdering :: GOrdering a b -> Ordering -- | Type class for comparable GADT-like structures. When 2 things are -- equal, must return a witness that their parameter types are equal as -- well (GEQ). class GEq f => GCompare f gcompare :: GCompare f => f a -> f b -> GOrdering a b defaultCompare :: GCompare f => f a -> f b -> Ordering -- | Propositional equality. If a :~: b is inhabited by some -- terminating value, then the type a is the same as the type -- b. To use this equality in practice, pattern-match on the -- a :~: b to get out the Refl constructor; in the body -- of the pattern-match, the compiler knows that a ~ b. -- -- Since: 4.7.0.0 data (:~:) (a :: k) (b :: k) :: k -> k -> * Refl :: (:~:) k a1 a1 instance [safe] Typeable GOrdering instance [safe] GCompare ((:=) a) instance [safe] GRead (GOrdering a) instance [safe] GShow (GOrdering a) instance [safe] Show (GOrdering a b) instance [safe] Ord (GOrdering a b) instance [safe] Eq (GOrdering a b) instance [safe] GEq ((:=) a) instance [safe] GRead ((:=) a) instance [safe] GShow ((:=) a) module Data.Some data Some tag This :: !(tag t) -> Some tag withSome :: Some tag -> (forall a. tag a -> b) -> b instance GCompare tag => Ord (Some tag) instance GEq tag => Eq (Some tag) instance GRead f => Read (Some f) instance GShow tag => Show (Some tag) module Data.Dependent.Sum -- | A basic dependent sum type; the first component is a tag that -- specifies the type of the second; for example, think of a GADT such -- as: -- --
-- data Tag a where -- AString :: Tag String -- AnInt :: Tag Int ---- -- Then, we have the following valid expressions of type DSum -- Tag: -- --
-- AString :=> "hello!" -- AnInt :=> 42 ---- -- And we can write functions that consume DSum Tag values by -- matching, such as: -- --
-- toString :: DSum Tag -> String -- toString (AString :=> str) = str -- toString (AnInt :=> int) = show int ---- -- By analogy to the (key => value) construction for dictionary -- entries in many dynamic languages, we use (key :=> value) as the -- constructor for dependent sums. The :=> operator has very low -- precedence and binds to the right, so if the Tag GADT is -- extended with an additional constructor Rec :: Tag (DSum -- Tag), then Rec :=> AnInt :=> 3 + 4 is parsed as -- would be expected (Rec :=> (AnInt :=> (3 + 4))) and has -- type DSum Tag. Its precedence is just above that of $, -- so foo bar $ AString :=> "eep" is equivalent to foo -- bar (AString :=> "eep"). data DSum tag f (:=>) :: !(tag a) -> f a -> DSum tag f (==>) :: Applicative f => tag a -> a -> DSum tag f -- | In order to make a Show instance for DSum tag, -- tag must be able to show itself as well as any value of the -- tagged type. GShow together with this class provides the -- interface by which it can do so. -- -- ShowTag tag => t is conceptually equivalent to something -- like this imaginary syntax: (forall a. Inhabited (tag a) => -- Show a) => t, where Inhabited is an imaginary -- predicate that characterizes non-empty types, and a does not -- occur free in t. -- -- The Tag example type introduced in the DSum section -- could be given the following instances: -- --
-- instance GShow Tag where -- gshowsPrec _p AString = showString "AString" -- gshowsPrec _p AnInt = showString "AnInt" -- instance ShowTag Tag where -- showTaggedPrec AString = showsPrec -- showTaggedPrec AnInt = showsPrec --class GShow tag => ShowTag tag f showTaggedPrec :: ShowTag tag f => tag a -> Int -> f a -> ShowS class GRead tag => ReadTag tag f readTaggedPrec :: ReadTag tag f => tag a -> Int -> ReadS (f a) -- | In order to make a Read instance for DSum tag, -- tag must be able to parse itself as well as any value of the -- tagged type. GRead together with this class provides the -- interface by which it can do so. -- -- ReadTag tag => t is conceptually equivalent to something -- like this imaginary syntax: (forall a. Inhabited (tag a) => -- Read a) => t, where Inhabited is an imaginary -- predicate that characterizes non-empty types, and a does not -- occur free in t. -- -- The Tag example type introduced in the DSum section -- could be given the following instances: -- --
-- instance GRead Tag where -- greadsPrec _p str = case tag of -- "AString" -> [(\k -> k AString, rest)] -- "AnInt" -> [(\k -> k AnInt, rest)] -- _ -> [] -- where (tag, rest) = break isSpace str -- instance ReadTag Tag where -- readTaggedPrec AString = readsPrec -- readTaggedPrec AnInt = readsPrec ---- | In order to test DSum tag for equality, tag must -- know how to test both itself and its tagged values for equality. -- EqTag defines the interface by which they are expected to do -- so. -- -- Continuing the Tag example from the DSum section, we -- can define: -- --
-- instance GEq Tag where -- geq AString AString = Just Refl -- geq AnInt AnInt = Just Refl -- geq _ _ = Nothing -- instance EqTag Tag where -- eqTagged AString AString = (==) -- eqTagged AnInt AnInt = (==) ---- -- Note that eqTagged is not called until after the tags have been -- compared, so it only needs to consider the cases where gcompare -- returns GEQ. class GEq tag => EqTag tag f eqTagged :: EqTag tag f => tag a -> tag a -> f a -> f a -> Bool -- | In order to compare DSum tag values, tag must know -- how to compare both itself and its tagged values. OrdTag -- defines the interface by which they are expected to do so. -- -- Continuing the Tag example from the EqTag section, we -- can define: -- --
-- instance GCompare Tag where -- gcompare AString AString = GEQ -- gcompare AString AnInt = GLT -- gcompare AnInt AString = GGT -- gcompare AnInt AnInt = GEQ -- instance OrdTag Tag where -- compareTagged AString AString = compare -- compareTagged AnInt AnInt = compare ---- -- As with eqTagged, compareTagged only needs to consider -- cases where gcompare returns GEQ. class (EqTag tag f, GCompare tag) => OrdTag tag f compareTagged :: OrdTag tag f => tag a -> tag a -> f a -> f a -> Ordering instance [safe] Typeable DSum instance [safe] OrdTag tag f => Ord (DSum tag f) instance [safe] Ord (f a) => OrdTag ((:=) a) f instance [safe] EqTag tag f => Eq (DSum tag f) instance [safe] Eq (f a) => EqTag ((:=) a) f instance [safe] ReadTag tag f => Read (DSum tag f) instance [safe] Read (f a) => ReadTag ((:=) a) f instance [safe] ShowTag tag f => Show (DSum tag f) instance [safe] Show (f a) => ShowTag (GOrdering a) f instance [safe] Show (f a) => ShowTag ((:=) a) f