HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Moduledependent-sum-0.6.2.0Haskell98

Data.Dependent.Sum

  • 5 types
  • 7 values
datadata DSum (tag :: k -> Type) (f :: k -> Type)
#

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").

Constructors

  • forall a. tag a :=> f ainfixr 1
Instances4Eq, Ord, Read, Show
typetype ShowTag (tag :: k' -> Type) (f :: k' -> Type) = (GShow tag, Has' Show tag f)
#

Deprecated. Instead of 'ShowTag tag f', use '(GShow tag, Has' Show tag f)'

typetype ReadTag (tag :: k' -> Type) (f :: k' -> Type) = (GRead tag, Has' Read tag f)
#

Deprecated. Instead of 'ReadTag tag f', use '(GRead tag, Has' Read tag f)'

typetype EqTag (tag :: k' -> Type) (f :: k' -> Type) = (GEq tag, Has' Eq tag f)
#

Deprecated. Instead of 'EqTag tag f', use '(GEq tag, Has' Eq tag f)'

typetype OrdTag (tag :: k' -> Type) (f :: k' -> Type) = (GCompare tag, Has' Eq tag f, Has' Ord tag f)
#

Deprecated. Instead of 'OrdTag tag f', use '(GCompare tag, Has' Eq tag f, Has' Ord tag f)'