-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Dependent sum type -- -- A dependent sum is a generalization of a particular way of thinking -- about the Either type. Either a b can be thought of -- as a 2-tuple (tag, value), where the value of the tag -- determines the type of the value. In particular, either tag = -- Left and value :: a or tag = Right and -- value :: b. -- -- This package allows you to define your own dependent sum types by -- using your own "tag" types. @package dependent-sum @version 0.6.1 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 newtype GReadResult t GReadResult :: (forall b. (forall a. t a -> b) -> b) -> GReadResult t [getGReadResult] :: GReadResult t -> forall b. (forall a. t a -> b) -> b -- | 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 -> [(GReadResult t, 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 -- |
-- >>> greadMaybe "InL Refl" mkSome :: Maybe (Some (Sum ((:~:) Int) ((:~:) Bool))) -- Just (Some (InL Refl)) ---- --
-- >>> greadMaybe "garbage" mkSome :: Maybe (Some ((:~:) Int)) -- Nothing --greadMaybe :: GRead t => String -> (forall a. t a -> b) -> Maybe b instance forall k (a :: k). Data.GADT.Show.GRead ((Data.Type.Equality.:~:) a) instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Show.GRead a, Data.GADT.Show.GRead b) => Data.GADT.Show.GRead (Data.Functor.Sum.Sum a b) instance forall k (a :: k). Data.GADT.Show.GShow ((Data.Type.Equality.:~:) a) instance Data.GADT.Show.GShow Data.Typeable.Internal.TypeRep instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Show.GShow a, Data.GADT.Show.GShow b) => Data.GADT.Show.GShow (Data.Functor.Sum.Sum a b) instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Show.GShow a, Data.GADT.Show.GShow b) => Data.GADT.Show.GShow (Data.Functor.Product.Product a b) module Data.GADT.Compare -- | 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 -- | 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 -- | 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 -- | Produce a witness of type-equality, if one exists. -- -- A handy idiom for using this would be to pattern-bind in the Maybe -- monad, eg.: -- --
-- extract :: GEq tag => tag a -> DSum tag -> Maybe a -- extract t1 (t2 :=> x) = do -- Refl <- geq t1 t2 -- return x ---- -- Or in a list comprehension: -- --
-- extractMany :: GEq tag => tag a -> [DSum tag] -> [a] -- extractMany t1 things = [ x | (t2 :=> x) <- things, Refl <- maybeToList (geq t1 t2)] ---- -- (Making use of the DSum type from Data.Dependent.Sum -- in both examples) geq :: GEq f => f a -> f b -> Maybe (a :~: b) -- | Backwards compatibility alias; as of GHC 7.8, this is the same as -- `(:~:)`. -- | Deprecated: use '(:~:)' from 'Data.Type,Equality'. type (:=) = (:~:) -- | 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 -- | TODO: Think of a better name -- -- This operation forgets the phantom types of a GOrdering value. weakenOrdering :: GOrdering a b -> Ordering 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. data (:~:) (a :: k) (b :: k) :: forall k. () => k -> k -> Type [Refl] :: forall k (a :: k) (b :: k). () => a :~: a infix 4 :~: instance forall k (a :: k). Data.GADT.Compare.GCompare ((Data.Type.Equality.:~:) a) instance Data.GADT.Compare.GCompare Data.Typeable.Internal.TypeRep instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Compare.GCompare a, Data.GADT.Compare.GCompare b) => Data.GADT.Compare.GCompare (Data.Functor.Sum.Sum a b) instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Compare.GCompare a, Data.GADT.Compare.GCompare b) => Data.GADT.Compare.GCompare (Data.Functor.Product.Product a b) instance forall k (a :: k) (b :: k). GHC.Classes.Eq (Data.GADT.Compare.GOrdering a b) instance forall k (a :: k) (b :: k). GHC.Classes.Ord (Data.GADT.Compare.GOrdering a b) instance forall k (a :: k) (b :: k). GHC.Show.Show (Data.GADT.Compare.GOrdering a b) instance forall k (a :: k). Data.GADT.Show.GShow (Data.GADT.Compare.GOrdering a) instance forall k (a :: k). Data.GADT.Show.GRead (Data.GADT.Compare.GOrdering a) instance forall k (a :: k). Data.GADT.Compare.GEq ((Data.Type.Equality.:~:) a) instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Compare.GEq a, Data.GADT.Compare.GEq b) => Data.GADT.Compare.GEq (Data.Functor.Sum.Sum a b) instance forall k (a :: k -> *) (b :: k -> *). (Data.GADT.Compare.GEq a, Data.GADT.Compare.GEq b) => Data.GADT.Compare.GEq (Data.Functor.Product.Product a b) instance Data.GADT.Compare.GEq Data.Typeable.Internal.TypeRep 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 Applicative -- f => DSum Tag f: -- --
-- AString ==> "hello!" -- AnInt ==> 42 ---- -- And we can write functions that consume DSum Tag f values by -- matching, such as: -- --
-- toString :: DSum Tag Identity -> String -- toString (AString :=> Identity str) = str -- toString (AnInt :=> Identity 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 :=> and ==> operators have -- very low precedence and bind to the right, so if the Tag GADT -- is extended with an additional constructor Rec :: Tag (DSum Tag -- Identity), then Rec ==> AnInt ==> 3 + 4 is parsed -- as would be expected (Rec ==> (AnInt ==> (3 + 4))) and -- has type DSum Identity 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 infixr 1 :=> (==>) :: Applicative f => tag a -> a -> DSum tag f infixr 1 ==> -- | Deprecated: Instead of 'ShowTag tag f', use '(GShow tag, Has' Show -- tag f)' type ShowTag tag f = (GShow tag, Has' Show tag f) showTaggedPrec :: forall tag f a. (GShow tag, Has' Show tag f) => tag a -> Int -> f a -> ShowS -- | Deprecated: Instead of 'ReadTag tag f', use '(GRead tag, Has' Read -- tag f)' type ReadTag tag f = (GRead tag, Has' Read tag f) readTaggedPrec :: forall tag f a. (GRead tag, Has' Read tag f) => tag a -> Int -> ReadS (f a) -- | Deprecated: Instead of 'EqTag tag f', use '(GEq tag, Has' Eq tag -- f)' type EqTag tag f = (GEq tag, Has' Eq tag f) eqTaggedPrec :: forall tag f a. (GEq tag, Has' Eq tag f) => tag a -> tag a -> f a -> f a -> Bool eqTagged :: forall tag f a. EqTag tag f => tag a -> tag a -> f a -> f a -> Bool -- | Deprecated: Instead of 'OrdTag tag f', use '(GCompare tag, Has' Eq -- tag f, Has' Ord tag f)' type OrdTag tag f = (GCompare tag, Has' Eq tag f, Has' Ord tag f) compareTaggedPrec :: forall tag f a. (GCompare tag, Has' Eq tag f, Has' Ord tag f) => tag a -> tag a -> f a -> f a -> Ordering compareTagged :: forall tag f a. OrdTag tag f => tag a -> tag a -> f a -> f a -> Ordering instance forall k (tag :: k -> *) (f :: k -> *). (Data.GADT.Show.GShow tag, Data.Constraint.Extras.Has' GHC.Show.Show tag f) => GHC.Show.Show (Data.Dependent.Sum.DSum tag f) instance forall k (tag :: k -> *) (f :: k -> *). (Data.GADT.Show.GRead tag, Data.Constraint.Extras.Has' GHC.Read.Read tag f) => GHC.Read.Read (Data.Dependent.Sum.DSum tag f) instance forall k (tag :: k -> *) (f :: k -> *). (Data.GADT.Compare.GEq tag, Data.Constraint.Extras.Has' GHC.Classes.Eq tag f) => GHC.Classes.Eq (Data.Dependent.Sum.DSum tag f) instance forall k (tag :: k -> *) (f :: k -> *). (Data.GADT.Compare.GCompare tag, Data.Constraint.Extras.Has' GHC.Classes.Eq tag f, Data.Constraint.Extras.Has' GHC.Classes.Ord tag f) => GHC.Classes.Ord (Data.Dependent.Sum.DSum tag f) module Data.Some -- | Existential. This is type is useful to hide GADTs' parameters. -- --
-- >>> data Tag :: * -> * where TagInt :: Tag Int; TagBool :: Tag Bool -- -- >>> instance GShow Tag where gshowsPrec _ TagInt = showString "TagInt"; gshowsPrec _ TagBool = showString "TagBool" ---- -- You can either use PatternSynonyms -- --
-- >>> let x = Some TagInt -- -- >>> x -- Some TagInt ---- --
-- >>> case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String
-- "I"
--
--
-- or you can use functions
--
-- -- >>> let y = mkSome TagBool -- -- >>> y -- Some TagBool ---- --
-- >>> withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String
-- "B"
--
--
-- The implementation of mapSome is safe.
--
-- -- >>> let f :: Tag a -> Tag a; f TagInt = TagInt; f TagBool = TagBool -- -- >>> mapSome f y -- Some TagBool ---- -- but you can also use: -- --
-- >>> withSome y (mkSome . f) -- Some TagBool --data Some tag pattern Some :: tag a -> Some tag -- | Deprecated: Use Some instead pattern This :: tag a -> Some tag -- | Constructor. mkSome :: tag a -> Some tag -- | Eliminator. withSome :: Some tag -> (forall a. tag a -> b) -> b mapSome :: (forall t. f t -> g t) -> Some f -> Some g instance forall k (tag :: k -> *). Data.GADT.Show.GShow tag => GHC.Show.Show (Data.Some.Some tag) instance forall k (f :: k -> *). Data.GADT.Show.GRead f => GHC.Read.Read (Data.Some.Some f) instance forall k (tag :: k -> *). Data.GADT.Compare.GEq tag => GHC.Classes.Eq (Data.Some.Some tag) instance forall k (tag :: k -> *). Data.GADT.Compare.GCompare tag => GHC.Classes.Ord (Data.Some.Some tag)