Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data label := value = KnownSymbol label => (FldProxy label) := !value
- type Record lts = Rec (Sort lts)
- rnil :: Rec '[]
- rcons :: forall l t lts s sortedLts. (RecSize lts ~ s, sortedLts ~ Sort ((l := t) ': lts), KnownNat s, KnownNat (RecVecIdxPos l sortedLts), KeyDoesNotExist l lts, RecCopy lts lts sortedLts) => (l := t) -> Rec lts -> Rec sortedLts
- (&) :: forall l t lts s sortedLts. (RecSize lts ~ s, sortedLts ~ Sort ((l := t) ': lts), KnownNat s, KnownNat (RecVecIdxPos l sortedLts), KeyDoesNotExist l lts, RecCopy lts lts sortedLts) => (l := t) -> Rec lts -> Rec sortedLts
- fld :: FldProxy l -> FldProxy l
- type Has l lts v = (RecTy l lts ~ v, KnownNat (RecSize lts), KnownNat (RecVecIdxPos l lts))
- type family HasOf (req :: [*]) (lts :: [*]) :: Constraint where ...
- get :: forall l v lts. Has l lts v => FldProxy l -> Rec lts -> v
- (&.) :: forall l v lts. Has l lts v => Rec lts -> FldProxy l -> v
- set :: forall l v lts. Has l lts v => FldProxy l -> v -> Rec lts -> Rec lts
- modify :: forall l v lts. Has l lts v => FldProxy l -> (v -> v) -> Rec lts -> Rec lts
- getPath :: RecApplyPath k x => k -> Rec x -> RecDeepTy k x
- setPath :: RecApplyPath k x => k -> RecDeepTy k x -> Rec x -> Rec x
- modifyPath :: RecApplyPath k x => k -> (RecDeepTy k x -> RecDeepTy k x) -> Rec x -> Rec x
- class RecApplyPath p x
- data lbl :& more
- (&:) :: FldProxy q -> more -> q :& more
- (&:-) :: FldProxy q -> FldProxy r -> q :& FldProxy r
- combine :: forall lhs rhs sortRes. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs), sortRes ~ Sort (RecAppend lhs rhs), RecCopy lhs lhs sortRes, RecCopy rhs rhs sortRes) => Rec lhs -> Rec rhs -> Rec sortRes
- (++:) :: forall lhs rhs sortRes. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs), sortRes ~ Sort (RecAppend lhs rhs), RecCopy lhs lhs sortRes, RecCopy rhs rhs sortRes) => Rec lhs -> Rec rhs -> Rec sortRes
- type RecAppend lhs rhs = RecAppendH lhs rhs rhs '[]
- reflectRec :: forall c r lts. RecApply lts lts c => Proxy c -> (forall a. c a => String -> a -> r) -> Rec lts -> [r]
- reflectRecFold :: forall c r lts. RecApply lts lts c => Proxy c -> (forall a. c a => String -> a -> r -> r) -> Rec lts -> r -> r
- class RecApply (rts :: [*]) (lts :: [*]) c where
- class FromNative a lts | a -> lts
- fromNative :: (Generic a, FromNative (Rep a) lts) => a -> Rec lts
- class ToNative a lts
- toNative :: (Generic a, ToNative (Rep a) lts) => Rec lts -> a
- asksR :: (Has lbl lts v, MonadReader (Rec lts) m) => FldProxy lbl -> m v
- asksRP :: (RecApplyPath k x, MonadReader (Rec x) m) => k -> m (RecDeepTy k x)
- getsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> m v
- setsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> v -> m ()
- modifiesR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> (v -> v) -> m ()
- getsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> m (RecDeepTy k x)
- setsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> RecDeepTy k x -> m ()
- modifiesRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> (RecDeepTy k x -> RecDeepTy k x) -> m ()
- lens :: Has l lts v => FldProxy l -> Lens (Rec lts) (Rec lts) v v
- data Rec (lts :: [*])
- class RecCopy (pts :: [*]) (lts :: [*]) (rts :: [*])
- type family RecTyIdxH (i :: Nat) (l :: Symbol) (lts :: [*]) :: Nat where ...
- showRec :: forall lts. RecApply lts lts Show => Rec lts -> [(String, String)]
- class RecKeys (lts :: [*]) where
- recKeys :: forall t (lts :: [*]). RecKeys lts => t lts -> [String]
- class RecEq (rts :: [*]) (lts :: [*]) where
- recToValue :: forall lts. RecApply lts lts ToJSON => Rec lts -> Value
- recToEncoding :: forall lts. RecApply lts lts ToJSON => Rec lts -> Encoding
- recJsonParser :: forall lts s. (RecSize lts ~ s, KnownNat s, RecJsonParse lts) => Value -> Parser (Rec lts)
- class RecJsonParse (lts :: [*]) where
- class RecNfData (lts :: [*]) (rts :: [*]) where
- type family RecSize (lts :: [*]) :: Nat where ...
- type family RemoveAccessTo (l :: Symbol) (lts :: [*]) :: [*] where ...
- data FldProxy (t :: Symbol) = FldProxy
- type family RecDeepTy (ps :: r) (lts :: [*]) :: * where ...
- type family RecAll (c :: u -> Constraint) (rs :: [u]) :: Constraint where ...
- type family KeyDoesNotExist (l :: Symbol) (lts :: [*]) :: Constraint where ...
- type Sort xs = FieldListSort xs
Basics
data label := value infix 6 Source #
Field named l
labels value of type t
adapted from the awesome labels package.
Example: (#name := "Chris") :: ("name" := String)
KnownSymbol label => (FldProxy label) := !value infix 6 |
(RecEq rts (RemoveAccessTo l lts), Has * l rts v, Eq v) => RecEq rts ((:) * ((:=) l t) lts) Source # | |
(KnownSymbol l, RecApply rts (RemoveAccessTo l lts) c, Has * l rts v, c v) => RecApply rts ((:) * ((:=) l t) lts) c Source # | |
KnownSymbol name => FromNative k (S1 k (MetaSel (Just Symbol name) p s l) (Rec0 k t)) ((:) * ((:=) name t) ([] *)) Source # | |
(KnownSymbol lbl, ToJSON t, ToJSON (JsonTaggedVariant ts)) => ToJSON (JsonTaggedVariant ((:) * ((:=) lbl t) ts)) # | |
(FromJSON t, FromJSON (JsonTaggedVariant ts), KnownSymbol lbl) => FromJSON (JsonTaggedVariant ((:) * ((:=) lbl t) ts)) # | |
Eq value => Eq ((:=) label value) Source # | |
Ord value => Ord ((:=) label value) Source # | |
Show t => Show ((:=) l t) Source # | |
(KnownSymbol l, FromJSON t, RecJsonParse lts, (~) Nat (RecSize lts) s, KnownNat s, KeyDoesNotExist l lts) => RecJsonParse ((:) * ((:=) l t) lts) Source # | |
(KnownSymbol l, RecKeys lts) => RecKeys ((:) * ((:=) l t) lts) Source # | |
(Has * l rts v, NFData v, RecNfData (RemoveAccessTo l lts) rts) => RecNfData ((:) * ((:=) l t) lts) rts Source # | |
(Has * l rts t, Has * l lts t, RecCopy (RemoveAccessTo l ((:) * ((:=) l t) pts)) lts rts) => RecCopy ((:) * ((:=) l t) pts) lts rts Source # | |
type RecKeysT ((:) * ((:=) l t) lts) Source # | |
type Record lts = Rec (Sort lts) Source #
The core record type. Prefer this type when manually writing type signatures
rcons :: forall l t lts s sortedLts. (RecSize lts ~ s, sortedLts ~ Sort ((l := t) ': lts), KnownNat s, KnownNat (RecVecIdxPos l sortedLts), KeyDoesNotExist l lts, RecCopy lts lts sortedLts) => (l := t) -> Rec lts -> Rec sortedLts Source #
Prepend a record entry to a record Rec
(&) :: forall l t lts s sortedLts. (RecSize lts ~ s, sortedLts ~ Sort ((l := t) ': lts), KnownNat s, KnownNat (RecVecIdxPos l sortedLts), KeyDoesNotExist l lts, RecCopy lts lts sortedLts) => (l := t) -> Rec lts -> Rec sortedLts infixr 5 Source #
Alias for rcons
fld :: FldProxy l -> FldProxy l Source #
Helper function to allow to clearing specify unknown IsLabel
cases
type Has l lts v = (RecTy l lts ~ v, KnownNat (RecSize lts), KnownNat (RecVecIdxPos l lts)) Source #
Require a record to contain a label
type family HasOf (req :: [*]) (lts :: [*]) :: Constraint where ... Source #
Require a record to contain at least the listed labels
get :: forall l v lts. Has l lts v => FldProxy l -> Rec lts -> v Source #
Get an existing record field
set :: forall l v lts. Has l lts v => FldProxy l -> v -> Rec lts -> Rec lts Source #
Update an existing record field
modify :: forall l v lts. Has l lts v => FldProxy l -> (v -> v) -> Rec lts -> Rec lts Source #
Update an existing record field
getPath :: RecApplyPath k x => k -> Rec x -> RecDeepTy k x Source #
Perform a deep read. This is somewhat similar to using (&.), but is useful
when you want to share a RecPath
between getPath
, modifyPath
and/or setPath
setPath :: RecApplyPath k x => k -> RecDeepTy k x -> Rec x -> Rec x Source #
Perform a deep update, setting the key along the path to the desired value
modifyPath :: RecApplyPath k x => k -> (RecDeepTy k x -> RecDeepTy k x) -> Rec x -> Rec x Source #
Perform a deep update, transforming the value at the final key
class RecApplyPath p x Source #
setPath', getPath'
(&:-) :: FldProxy q -> FldProxy r -> q :& FldProxy r infixr 8 Source #
Specialized version of (&:) to help writing the last piece of the path w/o confusing the type checker
combine :: forall lhs rhs sortRes. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs), sortRes ~ Sort (RecAppend lhs rhs), RecCopy lhs lhs sortRes, RecCopy rhs rhs sortRes) => Rec lhs -> Rec rhs -> Rec sortRes Source #
Combine two records
(++:) :: forall lhs rhs sortRes. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs), sortRes ~ Sort (RecAppend lhs rhs), RecCopy lhs lhs sortRes, RecCopy rhs rhs sortRes) => Rec lhs -> Rec rhs -> Rec sortRes Source #
Alias for combine
Reflection
reflectRec :: forall c r lts. RecApply lts lts c => Proxy c -> (forall a. c a => String -> a -> r) -> Rec lts -> [r] Source #
Apply a function to each key element pair for a record
reflectRecFold :: forall c r lts. RecApply lts lts c => Proxy c -> (forall a. c a => String -> a -> r -> r) -> Rec lts -> r -> r Source #
Fold over all elements of a record
class RecApply (rts :: [*]) (lts :: [*]) c where Source #
Machinery needed to implement reflectRec
Native type interop
class FromNative a lts | a -> lts Source #
Conversion helper to bring a Haskell type to a record. Note that the
native Haskell type must be an instance of Generic
fromNative'
(FromNative k l lhs, FromNative k r rhs, (~) [*] lts (Sort (RecAppend lhs rhs)), RecCopy lhs lhs lts, RecCopy rhs rhs lts, KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat ((+) (RecSize lhs) (RecSize rhs))) => FromNative k ((:*:) k l r) lts Source # | |
FromNative k cs lts => FromNative k (C1 k m cs) lts Source # | |
FromNative k cs lts => FromNative k (D1 k m cs) lts Source # | |
KnownSymbol name => FromNative k (S1 k (MetaSel (Just Symbol name) p s l) (Rec0 k t)) ((:) * ((:=) name t) ([] *)) Source # | |
fromNative :: (Generic a, FromNative (Rep a) lts) => a -> Rec lts Source #
Convert a native Haskell type to a record
Conversion helper to bring a record back into a Haskell type. Note that the
native Haskell type must be an instance of Generic
toNative'
toNative :: (Generic a, ToNative (Rep a) lts) => Rec lts -> a Source #
Convert a record to a native Haskell type
MTL interop
asksR :: (Has lbl lts v, MonadReader (Rec lts) m) => FldProxy lbl -> m v Source #
Like asks
for MonadReader
, but you provide a record field you would like
to read from your environment
asksRP :: (RecApplyPath k x, MonadReader (Rec x) m) => k -> m (RecDeepTy k x) Source #
Like asks
for MonadReader
, but you provide a record field you would like
to read from your environment
getsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> m v Source #
Like gets
for MonadState
, but you provide a record field you would like
to read from your environment
setsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> v -> m () Source #
Similar to put
for MonadState
, but you only set a single record field
modifiesR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> (v -> v) -> m () Source #
Similar to modify
for MonadState
, but you update a single record field
getsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> m (RecDeepTy k x) Source #
Similar to gets
for MonadState
, but allows getting a value along a RecPath
setsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> RecDeepTy k x -> m () Source #
Similar to put
for MonadState
, but you only set a single record field
modifiesRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> (RecDeepTy k x -> RecDeepTy k x) -> m () Source #
Similar to modify
for MonadState
, but you update a single record field
Lens interop
lens :: Has l lts v => FldProxy l -> Lens (Rec lts) (Rec lts) v v Source #
Convert a field label to a lens
Machinery
showRec :: forall lts. RecApply lts lts Show => Rec lts -> [(String, String)] Source #
Convert all elements of a record to a String
recJsonParser :: forall lts s. (RecSize lts ~ s, KnownNat s, RecJsonParse lts) => Value -> Parser (Rec lts) Source #
class RecJsonParse (lts :: [*]) where Source #
Machinery to implement parseJSON
RecJsonParse ([] *) Source # | |
(KnownSymbol l, FromJSON t, RecJsonParse lts, (~) Nat (RecSize lts) s, KnownNat s, KeyDoesNotExist l lts) => RecJsonParse ((:) * ((:=) l t) lts) Source # | |
type family RemoveAccessTo (l :: Symbol) (lts :: [*]) :: [*] where ... Source #
RemoveAccessTo l ((l := t) ': lts) = RemoveAccessTo l lts | |
RemoveAccessTo q ((l := t) ': lts) = (l := t) ': RemoveAccessTo l lts | |
RemoveAccessTo q '[] = '[] |
type family RecAll (c :: u -> Constraint) (rs :: [u]) :: Constraint where ... Source #
type family KeyDoesNotExist (l :: Symbol) (lts :: [*]) :: Constraint where ... Source #
KeyDoesNotExist l '[] = True ~ True | |
KeyDoesNotExist l ((l := t) ': lts) = TypeError (Text "Duplicate key " :<>: Text l) | |
KeyDoesNotExist q ((l := t) ': lts) = KeyDoesNotExist q lts |