úÎ!rHn4C      !"#$%&'()*+,-./0123456789:;<=>?@ABSafe,FQVÕ dependent-sumC0-like class for 1-type-parameter GADTs. Unlike 3, this one cannot be mechanically derived from a C instance because , must choose the phantom type based on the D being parsed. dependent-sumGReadS 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) dependent-sumE)-like class for 1-type-parameter GADTs. GShow t => ..." is equivalent to something like (forall a. Show (t a)) => ...R. 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    Safe&',1;<=FQSTV&f dependent-sumType class for comparable GADT-like structures. When 2 things are equal, must return a witness that their parameter types are equal as well (). dependent-sumÊ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. dependent-sumA class for type-contexts which contain enough information to (at least in some cases) decide the equality of types occurring within them. dependent-sum2Produce a witness of type-equality, if one exists.NA handy idiom for using this would be to pattern-bind in the Maybe monad, eg.: pextract :: GEq tag => tag a -> DSum tag -> Maybe a extract t1 (t2 :=> x) = do Refl <- geq t1 t2 return xOr 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) dependent-sumJBackwards compatibility alias; as of GHC 7.8, this is the same as `(:~:)`. dependent-sumIf f has a M instance, this function makes a suitable default implementation of '(==)'. dependent-sumIf f has a M instance, this function makes a suitable default implementation of '(/=)'. dependent-sumTODO: Think of a better name.This operation forgets the phantom types of a  value.Safe&',1;<=>?CFSTVlè' dependent-sumIn order to compare  DSum tag f values, tag? must know how to compare both itself and its tagged values. '= defines the interface by which they are expected to do so.Continuing the Tag example from the ) 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 = compareAs with *, (% only needs to consider cases where  returns .( dependent-sumGiven two values of type tag a (for which  returns ), return the F function for the type f a.) dependent-sumIn order to test  DSum tag f for equality, tagI must know how to test both itself and its tagged values for equality. )< defines the interface by which they are expected to do so.Continuing the Tag example from the / 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 *f is not called until after the tags have been compared, so it only needs to consider the cases where  returns .* dependent-sumGiven two values of type tag a (for which  returns ), return the G function for the type f a.- dependent-sumIn order to make a E instance for  DSum tag f, tagH must be able to show itself as well as any value of the tagged type. H together with this class provides the interface by which it can do so.ShowTag tag f => tG is conceptually equivalent to something like this imaginary syntax: 0(forall a. Inhabited (tag a) => Show (f a)) => t , where  InhabitedE is an imaginary predicate that characterizes non-empty types, and f and a do not occur free in t.The Tag example type introduced in the /? section could be given the following instances, among others: äinstance GShow Tag where gshowsPrec _p AString = showString "AString" gshowsPrec _p AnInt = showString "AnInt" instance ShowTag Tag [] where showTaggedPrec AString = showsPrec showTaggedPrec AnInt = showsPrec. dependent-sumGiven a value of type tag a , return the H function for the type f a./ 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 Int6Then, 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 Tag2 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 I, so foo bar $ AString ==> "eep" is equivalent to foo bar (AString ==> "eep").6 dependent-sumIn order to make a C instance for  DSum tag f, tagI must be able to parse itself as well as any value of the tagged type. H together with this class provides the interface by which it can do so.ReadTag tag f => tG is conceptually equivalent to something like this imaginary syntax: 0(forall a. Inhabited (tag a) => Read (f a)) => t , where  InhabitedE is an imaginary predicate that characterizes non-empty types, and f and a do not occur free in t.The Tag example type introduced in the /? section could be given the following instances, among others: ÿNinstance 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 '()*+,-./01 /01-.+,)*'(0111 Trustworthy %&',FQVen;=<>;=<=<>J       !"#$%&'()*+,-./0123456789:;<=>?@ABACDEFGHIJKLMNOPNOQLRJST(dependent-sum-0.5-Hu1PkqA8V7QDR4HnhhVY9WData.GADT.CompareData.GADT.ShowData.Dependent.Sum Data.SomebaseData.Type.EqualityRefl:~:GRead greadsPrecGReadS GReadResultgetGReadResultGShow gshowsPrecgshowsgshowgreadsgread$fGShowkTypeRepGComparegcompare GOrderingGLTGEQGGTGEqgeq:= defaultEq defaultNeqweakenOrderingdefaultCompare $fGReadk:~: $fGShowk:~: $fGEqkTypeRep $fGEqk:~:$fGReadkGOrdering$fGShowkGOrdering$fShowGOrdering$fOrdGOrdering $fEqGOrdering$fGComparekTypeRep$fGComparek:~:OrdTag compareTaggedEqTageqTaggedReadTagreadTaggedPrecShowTagshowTaggedPrecDSum:=>==> $fShowDSum$fShowTagkGOrderingf$fShowTagk:~:f $fReadDSum$fReadTagk:~:f$fEqDSum $fEqTagk:~:f $fOrdDSum $fOrdTagk:~:fSomeThiswithSome $fOrdSome$fEqSome $fReadSome $fShowSomeGHC.ReadReadGHC.BaseStringGHC.ShowShowghc-prim GHC.Classescompare== showsPrec$