composite-base-0.5.1.0: Shared utilities for composite-* packages.

Safe HaskellNone
LanguageHaskell2010

Composite.Record

Synopsis

Documentation

data Rec u a b :: forall u. (u -> *) -> [u] -> * where #

A record is parameterized by a universe u, an interpretation f and a list of rows rs. The labels or indices of the record are given by inhabitants of the kind u; the type of values at any label r :: u is given by its interpretation f r :: *.

Constructors

RNil :: Rec u a ([] u) 
(:&) :: Rec u a ((:) u r rs) infixr 7 

Instances

MonadContext c ((->) (Record c)) Source # 

Methods

askContext :: Record c -> Record c Source #

localContext :: (Record c -> Record c) -> (Record c -> a) -> Record c -> a Source #

TestCoercion u f => TestCoercion [u] (Rec u f) 

Methods

testCoercion :: f a -> f b -> Maybe (Coercion (Rec u f) a b) #

TestEquality u f => TestEquality [u] (Rec u f) 

Methods

testEquality :: f a -> f b -> Maybe ((Rec u f :~: a) b) #

Eq (Rec u f ([] u)) 

Methods

(==) :: Rec u f [u] -> Rec u f [u] -> Bool #

(/=) :: Rec u f [u] -> Rec u f [u] -> Bool #

(Eq (f r), Eq (Rec a f rs)) => Eq (Rec a f ((:) a r rs)) 

Methods

(==) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

(/=) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

Ord (Rec u f ([] u)) 

Methods

compare :: Rec u f [u] -> Rec u f [u] -> Ordering #

(<) :: Rec u f [u] -> Rec u f [u] -> Bool #

(<=) :: Rec u f [u] -> Rec u f [u] -> Bool #

(>) :: Rec u f [u] -> Rec u f [u] -> Bool #

(>=) :: Rec u f [u] -> Rec u f [u] -> Bool #

max :: Rec u f [u] -> Rec u f [u] -> Rec u f [u] #

min :: Rec u f [u] -> Rec u f [u] -> Rec u f [u] #

(Ord (f r), Ord (Rec a f rs)) => Ord (Rec a f ((:) a r rs)) 

Methods

compare :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Ordering #

(<) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

(<=) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

(>) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

(>=) :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Bool #

max :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) #

min :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) #

RecAll u f rs Show => Show (Rec u f rs)

Records may be shown insofar as their points may be shown. reifyConstraint is used to great effect here.

Methods

showsPrec :: Int -> Rec u f rs -> ShowS #

show :: Rec u f rs -> String #

showList :: [Rec u f rs] -> ShowS #

Monoid (Rec u f ([] u)) 

Methods

mempty :: Rec u f [u] #

mappend :: Rec u f [u] -> Rec u f [u] -> Rec u f [u] #

mconcat :: [Rec u f [u]] -> Rec u f [u] #

(Monoid (f r), Monoid (Rec a f rs)) => Monoid (Rec a f ((:) a r rs)) 

Methods

mempty :: Rec a f ((a ': r) rs) #

mappend :: Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) -> Rec a f ((a ': r) rs) #

mconcat :: [Rec a f ((a ': r) rs)] -> Rec a f ((a ': r) rs) #

Storable (Rec u f ([] u)) 

Methods

sizeOf :: Rec u f [u] -> Int #

alignment :: Rec u f [u] -> Int #

peekElemOff :: Ptr (Rec u f [u]) -> Int -> IO (Rec u f [u]) #

pokeElemOff :: Ptr (Rec u f [u]) -> Int -> Rec u f [u] -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Rec u f [u]) #

pokeByteOff :: Ptr b -> Int -> Rec u f [u] -> IO () #

peek :: Ptr (Rec u f [u]) -> IO (Rec u f [u]) #

poke :: Ptr (Rec u f [u]) -> Rec u f [u] -> IO () #

(Storable (f r), Storable (Rec a f rs)) => Storable (Rec a f ((:) a r rs)) 

Methods

sizeOf :: Rec a f ((a ': r) rs) -> Int #

alignment :: Rec a f ((a ': r) rs) -> Int #

peekElemOff :: Ptr (Rec a f ((a ': r) rs)) -> Int -> IO (Rec a f ((a ': r) rs)) #

pokeElemOff :: Ptr (Rec a f ((a ': r) rs)) -> Int -> Rec a f ((a ': r) rs) -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Rec a f ((a ': r) rs)) #

pokeByteOff :: Ptr b -> Int -> Rec a f ((a ': r) rs) -> IO () #

peek :: Ptr (Rec a f ((a ': r) rs)) -> IO (Rec a f ((a ': r) rs)) #

poke :: Ptr (Rec a f ((a ': r) rs)) -> Rec a f ((a ': r) rs) -> IO () #

type Record = Rec Identity Source #

The type of regular plain records where each field has a value, equal to Rec Identity.

pattern (:*:) :: forall a rs s. a -> Rec * Identity rs -> Rec * Identity ((:) * ((:->) s a) rs) infixr 5 Source #

Bidirectional pattern matching the first field of a record using :-> values and the Identity functor.

This pattern is bidirectional meaning you can use it either as a pattern or a constructor, e.g.

  let rec = 123 :*: Just "foo" :*: RNil
      foo :*: bar :*: RNil = rec

Mnemonic: * for products.

pattern (:^:) :: forall f a rs s. Functor f => f a -> Rec * f rs -> Rec * f ((:) * ((:->) s a) rs) infixr 5 Source #

Bidirectional pattern matching the first field of a record using :-> values and any functor.

This pattern is bidirectional meaning you can use it either as a pattern or a constructor, e.g.

  let rec = Just 123 :^: Just "foo" :^: RNil
      Just foo :^: Just bar :^: RNil = rec

Mnemonic: ^ for products (record) of products (functor).

newtype s :-> a Source #

Some value of type a tagged with a symbol indicating its field name or label. Used as the usual type of elements in a Rec or Record.

Recommended pronunciation: record val.

Constructors

Val 

Fields

Instances

Monad ((:->) s) Source # 

Methods

(>>=) :: (s :-> a) -> (a -> s :-> b) -> s :-> b #

(>>) :: (s :-> a) -> (s :-> b) -> s :-> b #

return :: a -> s :-> a #

fail :: String -> s :-> a #

Functor ((:->) s) Source # 

Methods

fmap :: (a -> b) -> (s :-> a) -> s :-> b #

(<$) :: a -> (s :-> b) -> s :-> a #

Applicative ((:->) s) Source # 

Methods

pure :: a -> s :-> a #

(<*>) :: (s :-> (a -> b)) -> (s :-> a) -> s :-> b #

(*>) :: (s :-> a) -> (s :-> b) -> s :-> b #

(<*) :: (s :-> a) -> (s :-> b) -> s :-> a #

Foldable ((:->) s) Source # 

Methods

fold :: Monoid m => (s :-> m) -> m #

foldMap :: Monoid m => (a -> m) -> (s :-> a) -> m #

foldr :: (a -> b -> b) -> b -> (s :-> a) -> b #

foldr' :: (a -> b -> b) -> b -> (s :-> a) -> b #

foldl :: (b -> a -> b) -> b -> (s :-> a) -> b #

foldl' :: (b -> a -> b) -> b -> (s :-> a) -> b #

foldr1 :: (a -> a -> a) -> (s :-> a) -> a #

foldl1 :: (a -> a -> a) -> (s :-> a) -> a #

toList :: (s :-> a) -> [a] #

null :: (s :-> a) -> Bool #

length :: (s :-> a) -> Int #

elem :: Eq a => a -> (s :-> a) -> Bool #

maximum :: Ord a => (s :-> a) -> a #

minimum :: Ord a => (s :-> a) -> a #

sum :: Num a => (s :-> a) -> a #

product :: Num a => (s :-> a) -> a #

Traversable ((:->) s) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> (s :-> a) -> f (s :-> b) #

sequenceA :: Applicative f => (s :-> f a) -> f (s :-> a) #

mapM :: Monad m => (a -> m b) -> (s :-> a) -> m (s :-> b) #

sequence :: Monad m => (s :-> m a) -> m (s :-> a) #

Bounded a => Bounded ((:->) s a) Source # 

Methods

minBound :: s :-> a #

maxBound :: s :-> a #

Enum a => Enum ((:->) s a) Source # 

Methods

succ :: (s :-> a) -> s :-> a #

pred :: (s :-> a) -> s :-> a #

toEnum :: Int -> s :-> a #

fromEnum :: (s :-> a) -> Int #

enumFrom :: (s :-> a) -> [s :-> a] #

enumFromThen :: (s :-> a) -> (s :-> a) -> [s :-> a] #

enumFromTo :: (s :-> a) -> (s :-> a) -> [s :-> a] #

enumFromThenTo :: (s :-> a) -> (s :-> a) -> (s :-> a) -> [s :-> a] #

Eq a => Eq ((:->) s a) Source # 

Methods

(==) :: (s :-> a) -> (s :-> a) -> Bool #

(/=) :: (s :-> a) -> (s :-> a) -> Bool #

Floating a => Floating ((:->) s a) Source # 

Methods

pi :: s :-> a #

exp :: (s :-> a) -> s :-> a #

log :: (s :-> a) -> s :-> a #

sqrt :: (s :-> a) -> s :-> a #

(**) :: (s :-> a) -> (s :-> a) -> s :-> a #

logBase :: (s :-> a) -> (s :-> a) -> s :-> a #

sin :: (s :-> a) -> s :-> a #

cos :: (s :-> a) -> s :-> a #

tan :: (s :-> a) -> s :-> a #

asin :: (s :-> a) -> s :-> a #

acos :: (s :-> a) -> s :-> a #

atan :: (s :-> a) -> s :-> a #

sinh :: (s :-> a) -> s :-> a #

cosh :: (s :-> a) -> s :-> a #

tanh :: (s :-> a) -> s :-> a #

asinh :: (s :-> a) -> s :-> a #

acosh :: (s :-> a) -> s :-> a #

atanh :: (s :-> a) -> s :-> a #

log1p :: (s :-> a) -> s :-> a #

expm1 :: (s :-> a) -> s :-> a #

log1pexp :: (s :-> a) -> s :-> a #

log1mexp :: (s :-> a) -> s :-> a #

Fractional a => Fractional ((:->) s a) Source # 

Methods

(/) :: (s :-> a) -> (s :-> a) -> s :-> a #

recip :: (s :-> a) -> s :-> a #

fromRational :: Rational -> s :-> a #

Integral a => Integral ((:->) s a) Source # 

Methods

quot :: (s :-> a) -> (s :-> a) -> s :-> a #

rem :: (s :-> a) -> (s :-> a) -> s :-> a #

div :: (s :-> a) -> (s :-> a) -> s :-> a #

mod :: (s :-> a) -> (s :-> a) -> s :-> a #

quotRem :: (s :-> a) -> (s :-> a) -> (s :-> a, s :-> a) #

divMod :: (s :-> a) -> (s :-> a) -> (s :-> a, s :-> a) #

toInteger :: (s :-> a) -> Integer #

Num a => Num ((:->) s a) Source # 

Methods

(+) :: (s :-> a) -> (s :-> a) -> s :-> a #

(-) :: (s :-> a) -> (s :-> a) -> s :-> a #

(*) :: (s :-> a) -> (s :-> a) -> s :-> a #

negate :: (s :-> a) -> s :-> a #

abs :: (s :-> a) -> s :-> a #

signum :: (s :-> a) -> s :-> a #

fromInteger :: Integer -> s :-> a #

Ord a => Ord ((:->) s a) Source # 

Methods

compare :: (s :-> a) -> (s :-> a) -> Ordering #

(<) :: (s :-> a) -> (s :-> a) -> Bool #

(<=) :: (s :-> a) -> (s :-> a) -> Bool #

(>) :: (s :-> a) -> (s :-> a) -> Bool #

(>=) :: (s :-> a) -> (s :-> a) -> Bool #

max :: (s :-> a) -> (s :-> a) -> s :-> a #

min :: (s :-> a) -> (s :-> a) -> s :-> a #

Real a => Real ((:->) s a) Source # 

Methods

toRational :: (s :-> a) -> Rational #

RealFloat a => RealFloat ((:->) s a) Source # 

Methods

floatRadix :: (s :-> a) -> Integer #

floatDigits :: (s :-> a) -> Int #

floatRange :: (s :-> a) -> (Int, Int) #

decodeFloat :: (s :-> a) -> (Integer, Int) #

encodeFloat :: Integer -> Int -> s :-> a #

exponent :: (s :-> a) -> Int #

significand :: (s :-> a) -> s :-> a #

scaleFloat :: Int -> (s :-> a) -> s :-> a #

isNaN :: (s :-> a) -> Bool #

isInfinite :: (s :-> a) -> Bool #

isDenormalized :: (s :-> a) -> Bool #

isNegativeZero :: (s :-> a) -> Bool #

isIEEE :: (s :-> a) -> Bool #

atan2 :: (s :-> a) -> (s :-> a) -> s :-> a #

RealFrac a => RealFrac ((:->) s a) Source # 

Methods

properFraction :: Integral b => (s :-> a) -> (b, s :-> a) #

truncate :: Integral b => (s :-> a) -> b #

round :: Integral b => (s :-> a) -> b #

ceiling :: Integral b => (s :-> a) -> b #

floor :: Integral b => (s :-> a) -> b #

(KnownSymbol s, Show a) => Show ((:->) s a) Source # 

Methods

showsPrec :: Int -> (s :-> a) -> ShowS #

show :: (s :-> a) -> String #

showList :: [s :-> a] -> ShowS #

IsString a => IsString ((:->) s a) Source # 

Methods

fromString :: String -> s :-> a #

Semigroup a => Semigroup ((:->) s a) Source # 

Methods

(<>) :: (s :-> a) -> (s :-> a) -> s :-> a #

sconcat :: NonEmpty (s :-> a) -> s :-> a #

stimes :: Integral b => b -> (s :-> a) -> s :-> a #

Monoid a => Monoid ((:->) s a) Source # 

Methods

mempty :: s :-> a #

mappend :: (s :-> a) -> (s :-> a) -> s :-> a #

mconcat :: [s :-> a] -> s :-> a #

Storable a => Storable ((:->) s a) Source # 

Methods

sizeOf :: (s :-> a) -> Int #

alignment :: (s :-> a) -> Int #

peekElemOff :: Ptr (s :-> a) -> Int -> IO (s :-> a) #

pokeElemOff :: Ptr (s :-> a) -> Int -> (s :-> a) -> IO () #

peekByteOff :: Ptr b -> Int -> IO (s :-> a) #

pokeByteOff :: Ptr b -> Int -> (s :-> a) -> IO () #

peek :: Ptr (s :-> a) -> IO (s :-> a) #

poke :: Ptr (s :-> a) -> (s :-> a) -> IO () #

Wrapped ((:->) s0 a0) Source # 

Associated Types

type Unwrapped ((:->) s0 a0) :: * #

Methods

_Wrapped' :: Iso' (s0 :-> a0) (Unwrapped (s0 :-> a0)) #

(~) * ((:->) s0 a0) t0 => Rewrapped ((:->) s1 a1) t0 Source # 
(KnownSymbol s, ReifyNames rs) => ReifyNames ((:) * ((:->) s a) rs) Source # 

Methods

reifyNames :: Rec * f ((* ': (s :-> a)) rs) -> Rec * ((* :. *) ((,) Text) f) ((* ': (s :-> a)) rs) Source #

type Unwrapped ((:->) s0 a0) Source # 
type Unwrapped ((:->) s0 a0) = a0

val :: forall s a. a -> Identity (s :-> a) Source #

Convenience function to make an Identity (s :-> a) with a particular symbol, used for named field construction.

For example:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  type FBaz = "baz" :-> Double
  type MyRecord = [FFoo, FBar, FBaz]

  myRecord1 :: Record MyRecord
  myRecord1
    =  val "foo" 123
    :& val "bar" "foobar"
    :& val "baz" 3.21
    :& RNil

  myRecord2 :: Record MyRecord
  myRecord2 = rcast
    $  val "baz" 3.21
    :& val "foo" 123
    :& val "bar" "foobar"
    :& RNil

In this example, both myRecord1 and myRecord2 have the same value, since rcast can reorder records.

valName :: forall s a. KnownSymbol s => (s :-> a) -> Text Source #

Reflect the type level name of a named value s :-> a to a Text. For example, given "foo" :-> Int, yields "foo" :: Text

valWithName :: forall s a. KnownSymbol s => (s :-> a) -> (Text, a) Source #

Extract the value and reflect the name of a named value.

type RElem r rs = RElem r rs (RIndex r rs) Source #

Constraint expressing that r is in rs and providing the index of r in rs. Equal to RElem rs (RIndex r rs).

rlens :: (Functor g, RElem (s :-> a) rs, Functor g) => proxy (s :-> a) -> (a -> g a) -> Rec Identity rs -> g (Rec Identity rs) Source #

Lens to a particular field of a record using the Identity functor.

For example, given:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  fBar_ :: Proxy FBar
  fBar_ = Proxy

  rec :: Rec Identity '[FFoo, FBar]
  rec = 123 :*: "hello!" :*: Nil

Then:

  view (rlens fBar_)               rec == "hello!"
  set  (rlens fBar_) "goodbye!"    rec == 123 :*: "goodbye!" :*: Nil
  over (rlens fBar_) (map toUpper) rec == 123 :*: "HELLO!"   :*: Nil

rlens' :: (Functor f, Functor g, RElem (s :-> a) rs, Functor g) => proxy (s :-> a) -> (f a -> g (f a)) -> Rec f rs -> g (Rec f rs) Source #

Lens to a particular field of a record using any functor.

For example, given:

  type FFoo = "foo" :-> Int
  type FBar = "bar" :-> String
  fBar_ :: Proxy FBar
  fBar_ = Proxy

  rec :: Rec Maybe '[FFoo, FBar]
  rec = Just 123 :^: Just "hello!" :^: Nil

Then:

  view (rlens' fBar_)                      rec == Just "hello!"
  set  (rlens' fBar_) Nothing              rec == Just 123 :^: Nothing       :^: Nil
  over (rlens' fBar_) (fmap (map toUpper)) rec == Just 123 :^: Just "HELLO!" :^: Nil

type family AllHave (cs :: [u -> Constraint]) (as :: [u]) :: Constraint where ... Source #

Type function which produces the cross product of constraints cs and types as.

For example, AllHave '[Eq, Ord] '[Int, Text] is equivalent to (Eq Int, Ord Int, Eq Text, Ord Text)

Equations

AllHave cs '[] = () 
AllHave cs (a ': as) = (HasInstances a cs, AllHave cs as) 

type family HasInstances (a :: u) (cs :: [u -> Constraint]) :: Constraint where ... Source #

Type function which produces a constraint on a for each constraint in cs.

For example, HasInstances Int '[Eq, Ord] is equivalent to (Eq Int, Ord Int).

Equations

HasInstances a '[] = () 
HasInstances a (c ': cs) = (c a, HasInstances a cs) 

type family ValuesAllHave (cs :: [u -> Constraint]) (as :: [u]) :: Constraint where ... Source #

Type function which produces the cross product of constraints cs and the values carried in a record rs.

For example, ValuesAllHave '[Eq, Ord] '["foo" :-> Int, "bar" :-> Text] is equivalent to (Eq Int, Ord Int, Eq Text, Ord Text)

Equations

ValuesAllHave cs '[] = () 
ValuesAllHave cs ((s :-> a) ': as) = (HasInstances a cs, ValuesAllHave cs as) 

zipRecsWith :: (forall a. f a -> g a -> h a) -> Rec f as -> Rec g as -> Rec h as Source #

zipWith for Rec's.

reifyDicts :: forall cs f rs proxy. (AllHave cs rs, RecApplicative rs) => proxy cs -> (forall proxy' a. HasInstances a cs => proxy' a -> f a) -> Rec f rs Source #

Given a list of constraints cs, apply some function for each r in the target record type rs with proof that those constraints hold for r, generating a record with the result of each application.

recordToNonEmpty :: Rec (Const a) (r ': rs) -> NonEmpty a Source #

Convert a provably nonempty Rec (Const a) rs to a NonEmpty a.

class ReifyNames rs where Source #

Class which reifies the symbols of a record composed of :-> fields as Text.

Minimal complete definition

reifyNames

Methods

reifyNames :: Rec f rs -> Rec ((,) Text :. f) rs Source #

Given a Rec f rs where each r in rs is of the form s :-> a, make a record which adds the Text for each s.

Instances

ReifyNames ([] *) Source # 

Methods

reifyNames :: Rec * f [*] -> Rec * ((* :. *) ((,) Text) f) [*] Source #

(KnownSymbol s, ReifyNames rs) => ReifyNames ((:) * ((:->) s a) rs) Source # 

Methods

reifyNames :: Rec * f ((* ': (s :-> a)) rs) -> Rec * ((* :. *) ((,) Text) f) ((* ': (s :-> a)) rs) Source #

class RecWithContext ss ts where Source #

Class with rmap but which gives the natural transformation evidence that the value its working over is contained within the overall record ss.

Minimal complete definition

rmapWithContext

Methods

rmapWithContext :: proxy ss -> (forall r. r ss => f r -> g r) -> Rec f ts -> Rec g ts Source #

Apply a natural transformation from f to g to each field of the given record, except that the natural transformation can be mildly unnatural by having evidence that r is in ss.

Instances

RecWithContext ss ([] *) Source # 

Methods

rmapWithContext :: proxy ss -> (forall r. (* r) ss => f r -> g r) -> Rec * f [*] -> Rec * g [*] Source #

((∈) * r ss, RecWithContext ss ts) => RecWithContext ss ((:) * r ts) Source # 

Methods

rmapWithContext :: proxy ss -> (forall a. (* a) ss => f a -> g a) -> Rec * f ((* ': r) ts) -> Rec * g ((* ': r) ts) Source #

type family RDelete (r :: u) (rs :: [u]) where ... Source #

Type function which removes the first element r from a list rs, and doesn't expand if r is not present in rs.

Equations

RDelete r (r ': rs) = rs 
RDelete r (s ': rs) = s ': RDelete r rs 

type RDeletable r rs = (r rs, RDelete r rs rs) Source #

Constraint which reflects that an element r can be removed from rs using rdelete.

rdelete :: RDeletable r rs => proxy r -> Rec f rs -> Rec f (RDelete r rs) Source #

Remove an element r from a Rec f rs. Note this is just a type constrained rcast.