HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulevinyl-0.14.3Haskell2010

Data.Vinyl.CoRec

Co-records: open sum types.

Consider a record with three fields A, B, and C. A record is a product of its fields; that is, it contains all of them: A, B, and C. If we want to talk about a value whose type is one of those three types, it is any one of type A, B, or C. The type CoRec '[A,B,C] corresponds to this sum type.

  • 5 types
  • 3 classes
  • 24 values
  • Packagevinyl-0.14.3
  • Exports32
  • LanguageHaskell2010
  • LicenceMIT
  • SourceCoRec.hs
valuefoldCoRec
  1. :: forall (a :: k). RElem a ts (RIndex a ts) => f a -> b
  2. -> CoRec f ts
  3. -> b
#

Apply a function to a CoRec value. The function must accept any variant.

newtypenewtype Op b a
#

A function type constructor that takes its arguments in the reverse order.

Constructors

classclass ShowF (f :: k -> Type) (a :: k) where
#

Helper for writing a Show instance for CoRec. This lets us ask for a Show constraint on the type formed by applying a type constructor to a type index.

Methods

Instances1ShowF
  • Show (f a) => ShowF f aDefined in vinyl-0.14.3 · Data.Vinyl.CoRec
classclass FoldRec (ss :: [k]) (ts :: [k]) where
#

Fold a field selection function over a Rec.

Methods

Instances2FoldRec
  • FoldRec ss '[]Defined in vinyl-0.14.3 · Data.Vinyl.CoRec
  • (t ∈ ss, FoldRec ss ts) => FoldRec ss (t ': ts)Defined in vinyl-0.14.3 · Data.Vinyl.CoRec
valuecoRecMap :: (forall (x :: k). f x -> g x) -> CoRec f ts -> CoRec g ts
#

Apply a natural transformation to a variant.

valueonCoRec
  1. :: RPureConstrained c ts
  2. => forall (a :: k1). (a ∈ ts, c a) => f a -> g b
  3. -> CoRec f ts
  4. -> g b
#

Apply methods from a type class to a CoRec. Intended for use with TypeApplications, e.g. onCoRec @Show show r

valueonField
  1. :: RPureConstrained c ts
  2. => forall a. (a ∈ ts, c a) => a -> b
  3. -> Field ts
  4. -> b
#

Apply a type class method to a Field. Intended for use with TypeApplications, e.g. onField @Show show r.

Extracting values from a CoRec/Pattern matching on a CoRec

11 declarations
valuevariantIndexOf :: CoRec f ts -> Int
#

Compute a runtime Int index identifying the position of the variant held by a CoRec f ts in the type-level list ts.

valuematch :: CoRec Identity ts -> Handlers ts b -> b
#

Pattern match on a CoRec by specifying handlers for each case. Note that the order of the Handlers has to match the type level list (t:ts).

Example1 expression
:{let testCoRec = Col (Identity False) :: CoRec Identity [Int, String, Bool] inmatch testCoRec $      (H $ \i -> "my Int is the successor of " ++ show (i - 1))   :& (H $ \s -> "my String is: " ++ s)   :& (H $ \b -> "my Bool is not: " ++ show (not b) ++ " thus it is " ++ show b)   :& RNil:}"my Bool is not: True thus it is False"
classclass RIndex t ts ~ i => Match1 t (ts :: [Type]) (i :: Nat) where
#

Helper for handling a variant of a CoRec: either the function is applied to the variant or the type of the CoRec is refined to reflect the fact that the variant is not compatible with the type of the would-be handler.

Methods

Instances2Match1
  • Match1 t (t ': ts) 'ZDefined in vinyl-0.14.3 · Data.Vinyl.CoRec
  • (Match1 t ts i, RIndex t (s ': ts) ~ 'S i, RDelete t (s ': ts) ~ (s ': RDelete t ts)) => Match1 t (s ': ts) ('S i)Defined in vinyl-0.14.3 · Data.Vinyl.CoRec
newtypenewtype Handler b a
#

Newtype around functions for a to b

Constructors

  • H (a -> b)
typetype Handlers (ts :: [Type]) b = Rec (Handler b) ts
#

'Handlers ts b', is essentially a list of functions, one for each type in ts. All functions produce a value of type b. Hence, 'Handlers ts b' would represent something like the type-level list: [t -> b | t in ts ]

Safe Variants

3 declarations