HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulecomposite-base-0.8.3.0Haskell2010

Composite.CoRecord

Module containing the sum formulation companion to Composite.Records product formulation. Values of type CoRec f rs represent a single value f r for one of the rs in rs. Heavily based on the great work by Anthony Cowley in Frames.

Synopsis
datadata CoRec (a :: u -> Type) (b :: [u]) where

CoRef f rs represents a single value of type f r for some r in rs.

Constructors

Instances3Eq, Show, NFData
valuecoRec :: r ∈ rs => f r -> CoRec f rs

Inject a value f r into a CoRec f rs given that r is one of the valid rs.

Equivalent to CoVal the constructor, but exists to parallel field.

valuefoldCoVal
  1. :: forall (r :: u). RElem r rs (RIndex r rs) => f r -> b
  2. -> CoRec f rs
  3. -> b

Apply an extraction to whatever f r is contained in the given CoRec.

For example foldCoVal getConst :: CoRec (Const a) rs -> a.

classclass FoldRec (ss :: [u]) (ts :: [u]) where

Typeclass which allows folding ala foldMap over a Rec, using a CoRec as the accumulator.

Methods

  • foldRec :: (CoRec f ss -> CoRec f ss -> CoRec f ss) -> CoRec f ss -> Rec f ts -> CoRec f ss

    Given some combining function, an initial value, and a record, visit each field of the record using the combining function to accumulate the initial value or previous accumulation with the field of the record.

Instances2FoldRec
  • FoldRec ss '[]Defined in composite-base-0.8.3.0 · Composite.CoRecord
  • (t ∈ ss, FoldRec ss ts) => FoldRec ss (t ': ts)Defined in composite-base-0.8.3.0 · Composite.CoRecord
newtypenewtype Op b a

Helper newtype containing a function a -> b but with the type parameters flipped so Op b has a consistent codomain for a varying domain.

Constructors

typetype Cases' (f :: u -> Type) (rs :: [u]) b = Rec (Case' f b) rs

A record of Case' eliminators for each r in rs representing the pieces of a total function from CoRec f to b.

valuematchCoRec
  1. :: RecApplicative (r ': rs)
  2. => CoRec f (r ': rs)
  3. -> Cases' f (r ': rs) b
  4. -> b

Fold a CoRec f using Cases' which eliminate each possible value held by the CoRec, yielding the b produced by whichever case matches.

Equivalent to foldCoRec but with its arguments flipped so it can be written matchCoRec coRec $ cases.

newtypenewtype Case b a
#

Constructors

Instances1Contravariant
valuevalCase :: (a -> b) -> Case b (s :-> a)

Specialized type of Case for Val, with the type parameters in a convenient order for type application, e.g.:

  valCase "foo" ( a -> ...)
    :& valCase "bar" ( b -> ...)
    :& RNil
valuevalCase' :: Functor f => (f a -> b) -> Case' f b (s :-> a)

Specialized type of Case' for Val, with the type parameters in a convenient order for type application, e.g.:

  valCase' "foo" ( fa -> ...)
    :& valCase' "bar" ( fb -> ...)
    :& RNil
valuekeywordCase' :: KnownSymbol s => (Text -> a) -> Case a (s :-> ())

Make a Case' which yields the symbol text for a field s :-> () as projected through the given function. E.g.:

  keywordCase @"foo" (<> "bar") (Identity (Val ())) == "foobar"