Copyright | (c) Fumiaki Kinoshita 2018 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Flexible records and variants
Synopsis
- newtype Field (h :: v -> Type) (kv :: Assoc k v) = Field {}
- (@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v)
- (<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v)
- (@:>) :: FieldName k -> h v -> Field h (k :> v)
- (@==) :: FieldName (k :: Symbol) -> v -> Field Identity (k :> v)
- type FieldOptic k = forall kind. forall f p t xs (h :: kind -> Type) (v :: kind). (Extensible f p t, ExtensibleConstr t xs (Field h) (k :> v), Lookup xs k v, Labelling k p, Wrapper h) => Optic' p f (t xs (Field h)) (Repr h v)
- type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible '[k :> ()] (Field Proxy)) ()
- liftField :: (g (TargetOf kv) -> h (TargetOf kv)) -> Field g kv -> Field h kv
- liftField2 :: (f (TargetOf kv) -> g (TargetOf kv) -> h (TargetOf kv)) -> Field f kv -> Field g kv -> Field h kv
- type RecordOf h xs = xs :& Field h
- type Record xs = RecordOf Identity xs
- emptyRecord :: Record '[]
- type VariantOf h xs = xs :/ Field h
- type Variant xs = VariantOf Identity xs
- matchWithField :: (forall x. f x -> g x -> r) -> RecordOf f xs -> VariantOf g xs -> r
- matchField :: RecordOf (Match h r) xs -> VariantOf h xs -> r
- type family KeyOf (kv :: Assoc k v) :: k where ...
- proxyKeyOf :: proxy kv -> Proxy (KeyOf kv)
- stringKeyOf :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a
- type family TargetOf (kv :: Assoc k v) :: v where ...
- proxyTargetOf :: proxy kv -> Proxy (TargetOf kv)
- class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v)
- class pv (TargetOf kv) => TargetIs (pv :: k1 -> Constraint) (kv :: Assoc k k1)
- class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1)
- type AssocKey kv = KeyOf kv
- type AssocValue kv = TargetOf kv
- type ValueIs = TargetIs
- type KeyValue = KeyTargetAre
- proxyAssocKey :: proxy kv -> Proxy (KeyOf kv)
- stringAssocKey :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a
- proxyAssocValue :: proxy kv -> Proxy (TargetOf kv)
- data LabelPhantom s a b
- type family Labelling s p :: Constraint where ...
- data Inextensible (xs :: [k]) (h :: k -> Type)
Documentation
newtype Field (h :: v -> Type) (kv :: Assoc k v) Source #
Instances
(Lookup xs k2 v2, Wrapper h, Repr h v2 ~ a) => HasField (k2 :: k1) (RecordOf h xs) a Source # | |
Defined in Data.Extensible.Label | |
Unbox (h (TargetOf x)) => Vector Vector (Field h x) Source # | |
Defined in Data.Extensible.Field basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (Field h x) -> m (Vector (Field h x)) basicUnsafeThaw :: PrimMonad m => Vector (Field h x) -> m (Mutable Vector (PrimState m) (Field h x)) basicLength :: Vector (Field h x) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Field h x) -> Vector (Field h x) basicUnsafeIndexM :: Monad m => Vector (Field h x) -> Int -> m (Field h x) basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (Field h x) -> Vector (Field h x) -> m () | |
Unbox (h (TargetOf x)) => MVector MVector (Field h x) Source # | |
Defined in Data.Extensible.Field basicLength :: MVector s (Field h x) -> Int basicUnsafeSlice :: Int -> Int -> MVector s (Field h x) -> MVector s (Field h x) basicOverlaps :: MVector s (Field h x) -> MVector s (Field h x) -> Bool basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (Field h x)) basicInitialize :: PrimMonad m => MVector (PrimState m) (Field h x) -> m () basicUnsafeReplicate :: PrimMonad m => Int -> Field h x -> m (MVector (PrimState m) (Field h x)) basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> m (Field h x) basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> Field h x -> m () basicClear :: PrimMonad m => MVector (PrimState m) (Field h x) -> m () basicSet :: PrimMonad m => MVector (PrimState m) (Field h x) -> Field h x -> m () basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (Field h x) -> MVector (PrimState m) (Field h x) -> m () basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (Field h x) -> MVector (PrimState m) (Field h x) -> m () basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> m (MVector (PrimState m) (Field h x)) | |
(Bits r, FromBits r (h (TargetOf x))) => FromBits r (Field h x) Source # | |
Wrapper h => Wrapper (Field h :: Assoc k v -> Type) Source # | |
Forall (KeyTargetAre KnownSymbol (Instance1 FromJSON h)) xs => FromJSON (xs :& Nullable (Field h :: Assoc Symbol v -> Type)) | |
Defined in Data.Extensible.Dictionary | |
Forall (KeyTargetAre KnownSymbol (Instance1 FromJSON h)) xs => FromJSON (xs :& (Field h :: Assoc Symbol v -> Type)) |
|
Defined in Data.Extensible.Dictionary | |
Forall (KeyTargetAre KnownSymbol (Instance1 ToJSON h)) xs => ToJSON (xs :& Nullable (Field h :: Assoc Symbol v -> Type)) | |
Defined in Data.Extensible.Dictionary | |
Forall (KeyTargetAre KnownSymbol (Instance1 ToJSON h)) xs => ToJSON (xs :& (Field h :: Assoc Symbol v -> Type)) | |
Defined in Data.Extensible.Dictionary toJSON :: (xs :& Field h) -> Value toEncoding :: (xs :& Field h) -> Encoding toJSONList :: [xs :& Field h] -> Value toEncodingList :: [xs :& Field h] -> Encoding | |
Forall (KeyTargetAre KnownSymbol (Instance1 FromField h)) xs => FromNamedRecord (xs :& (Field h :: Assoc Symbol v -> Type)) | |
Defined in Data.Extensible.Dictionary parseNamedRecord :: NamedRecord -> Parser (xs :& Field h) | |
Forall (KeyTargetAre KnownSymbol (Instance1 ToField h)) xs => ToNamedRecord (xs :& (Field h :: Assoc Symbol v -> Type)) | |
Defined in Data.Extensible.Dictionary toNamedRecord :: (xs :& Field h) -> NamedRecord | |
Bounded (h (TargetOf kv)) => Bounded (Field h kv) Source # | |
Enum (h (TargetOf kv)) => Enum (Field h kv) Source # | |
Defined in Data.Extensible.Field succ :: Field h kv -> Field h kv # pred :: Field h kv -> Field h kv # fromEnum :: Field h kv -> Int # enumFrom :: Field h kv -> [Field h kv] # enumFromThen :: Field h kv -> Field h kv -> [Field h kv] # enumFromTo :: Field h kv -> Field h kv -> [Field h kv] # enumFromThenTo :: Field h kv -> Field h kv -> Field h kv -> [Field h kv] # | |
Eq (h (TargetOf kv)) => Eq (Field h kv) Source # | |
Floating (h (TargetOf kv)) => Floating (Field h kv) Source # | |
Defined in Data.Extensible.Field exp :: Field h kv -> Field h kv # log :: Field h kv -> Field h kv # sqrt :: Field h kv -> Field h kv # (**) :: Field h kv -> Field h kv -> Field h kv # logBase :: Field h kv -> Field h kv -> Field h kv # sin :: Field h kv -> Field h kv # cos :: Field h kv -> Field h kv # tan :: Field h kv -> Field h kv # asin :: Field h kv -> Field h kv # acos :: Field h kv -> Field h kv # atan :: Field h kv -> Field h kv # sinh :: Field h kv -> Field h kv # cosh :: Field h kv -> Field h kv # tanh :: Field h kv -> Field h kv # asinh :: Field h kv -> Field h kv # acosh :: Field h kv -> Field h kv # atanh :: Field h kv -> Field h kv # log1p :: Field h kv -> Field h kv # expm1 :: Field h kv -> Field h kv # | |
Fractional (h (TargetOf kv)) => Fractional (Field h kv) Source # | |
Integral (h (TargetOf kv)) => Integral (Field h kv) Source # | |
Defined in Data.Extensible.Field quot :: Field h kv -> Field h kv -> Field h kv # rem :: Field h kv -> Field h kv -> Field h kv # div :: Field h kv -> Field h kv -> Field h kv # mod :: Field h kv -> Field h kv -> Field h kv # quotRem :: Field h kv -> Field h kv -> (Field h kv, Field h kv) # divMod :: Field h kv -> Field h kv -> (Field h kv, Field h kv) # | |
Num (h (TargetOf kv)) => Num (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
Ord (h (TargetOf kv)) => Ord (Field h kv) Source # | |
Real (h (TargetOf kv)) => Real (Field h kv) Source # | |
Defined in Data.Extensible.Field toRational :: Field h kv -> Rational # | |
RealFloat (h (TargetOf kv)) => RealFloat (Field h kv) Source # | |
Defined in Data.Extensible.Field floatRadix :: Field h kv -> Integer # floatDigits :: Field h kv -> Int # floatRange :: Field h kv -> (Int, Int) # decodeFloat :: Field h kv -> (Integer, Int) # encodeFloat :: Integer -> Int -> Field h kv # exponent :: Field h kv -> Int # significand :: Field h kv -> Field h kv # scaleFloat :: Int -> Field h kv -> Field h kv # isInfinite :: Field h kv -> Bool # isDenormalized :: Field h kv -> Bool # isNegativeZero :: Field h kv -> Bool # | |
RealFrac (h (TargetOf kv)) => RealFrac (Field h kv) Source # | |
(KnownSymbol k, Wrapper h, Show (Repr h v2)) => Show (Field h (k :> v2)) Source # | Shows in |
Generic (Field h kv) Source # | |
Semigroup (h (TargetOf kv)) => Semigroup (Field h kv) Source # | |
Monoid (h (TargetOf kv)) => Monoid (Field h kv) Source # | |
Lift (h (TargetOf x)) => Lift (Field h x) Source # | |
Storable (h (TargetOf kv)) => Storable (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
NFData (h (TargetOf kv)) => NFData (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
Hashable (h (TargetOf kv)) => Hashable (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
(KnownSymbol k, Pretty (h v2)) => Pretty (Field h (k :> v2)) Source # | |
Defined in Data.Extensible.Field | |
Arbitrary (h (TargetOf kv)) => Arbitrary (Field h kv) Source # | |
FromJSON (h (TargetOf kv)) => FromJSON (Field h kv) Source # | |
Defined in Data.Extensible.Field parseJSON :: Value -> Parser (Field h kv) parseJSONList :: Value -> Parser [Field h kv] | |
ToJSON (h (TargetOf kv)) => ToJSON (Field h kv) Source # | |
Defined in Data.Extensible.Field toEncoding :: Field h kv -> Encoding toJSONList :: [Field h kv] -> Value toEncodingList :: [Field h kv] -> Encoding | |
FromField (h (TargetOf kv)) => FromField (Field h kv) Source # | |
Defined in Data.Extensible.Field parseField :: Field0 -> Parser (Field h kv) | |
ToField (h (TargetOf kv)) => ToField (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
Unbox (h (TargetOf x)) => Unbox (Field h x) Source # | |
Defined in Data.Extensible.Field | |
newtype MVector s (Field h x) Source # | |
Defined in Data.Extensible.Field | |
type Repr (Field h :: Assoc k v -> Type) (kv :: Assoc k v) Source # | |
type Rep (Field h kv) Source # | |
Defined in Data.Extensible.Field | |
newtype Vector (Field h x) Source # | |
Defined in Data.Extensible.Field | |
type BitWidth (Field h x) Source # | |
Defined in Data.Extensible.Bits |
(@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v) infix 1 Source #
Annotate a value by the field name.
foo :: Record
'["num" >: Int, "str" >: String]
foo = #num @= 42
<: #str @= "foo"
<: nil
(<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v) infix 1 Source #
(@:>) :: FieldName k -> h v -> Field h (k :> v) infix 1 Source #
Annotate a value by the field name without Wrapper
.
(@==) :: FieldName (k :: Symbol) -> v -> Field Identity (k :> v) infix 1 Source #
Kind-monomorphic, unwrapped version of @=
type FieldOptic k = forall kind. forall f p t xs (h :: kind -> Type) (v :: kind). (Extensible f p t, ExtensibleConstr t xs (Field h) (k :> v), Lookup xs k v, Labelling k p, Wrapper h) => Optic' p f (t xs (Field h)) (Repr h v) Source #
FieldOptic s
is a type of optics that points a field/constructor named s
.
The yielding fields can be
Lenses
for Record
s and
Prisms
for Variant
s.
FieldOptic
"foo" = Lookup xs "foo" a => Lens' (Record
xs) aFieldOptic
"foo" = Lookup xs "foo" a => Prism' (Variant
xs) a
FieldOptic
s can be generated using mkField
defined in the Data.Extensible.TH module.
type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible '[k :> ()] (Field Proxy)) () Source #
When you see this type as an argument, it expects a FieldLens
.
This type is used to resolve the name of the field internally.
liftField :: (g (TargetOf kv) -> h (TargetOf kv)) -> Field g kv -> Field h kv Source #
Lift a function for the content.
liftField2 :: (f (TargetOf kv) -> g (TargetOf kv) -> h (TargetOf kv)) -> Field f kv -> Field g kv -> Field h kv Source #
Lift a function for the content.
Records and variants
type RecordOf h xs = xs :& Field h Source #
The type of records which contain several fields.
RecordOf :: (v -> *) -> [Assoc k v] -> *
emptyRecord :: Record '[] Source #
An empty Record
.
type VariantOf h xs = xs :/ Field h Source #
The dual of RecordOf
VariantOf :: (v -> *) -> [Assoc k v] -> *
Matching
matchWithField :: (forall x. f x -> g x -> r) -> RecordOf f xs -> VariantOf g xs -> r Source #
Select a corresponding field of a variant.
Key / value
proxyKeyOf :: proxy kv -> Proxy (KeyOf kv) #
stringKeyOf :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a #
proxyTargetOf :: proxy kv -> Proxy (TargetOf kv) #
class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v) #
Instances
pk k2 => KeyIs (pk :: k1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
class pv (TargetOf kv) => TargetIs (pv :: k1 -> Constraint) (kv :: Assoc k k1) #
Instances
pv v2 => TargetIs (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1) #
Instances
(pk k2, pv v2) => KeyTargetAre (pk :: k1 -> Constraint) (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
deprecated
type AssocValue kv = TargetOf kv Source #
Deprecated: Use TargetOf instead
type KeyValue = KeyTargetAre Source #
Deprecated: Use KeyTargetAre instead
proxyAssocKey :: proxy kv -> Proxy (KeyOf kv) Source #
Deprecated: Use proxyKeyOf instead
stringAssocKey :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a Source #
Deprecated: Use stringKeyOf instead
proxyAssocValue :: proxy kv -> Proxy (TargetOf kv) Source #
Deprecated: Use proxyTargetOf instead
Internal
data LabelPhantom s a b Source #
A ghostly type which spells the field name
Instances
Profunctor (LabelPhantom s :: Type -> Type -> Type) Source # | |
Defined in Data.Extensible.Field dimap :: (a -> b) -> (c -> d) -> LabelPhantom s b c -> LabelPhantom s a d lmap :: (a -> b) -> LabelPhantom s b c -> LabelPhantom s a c rmap :: (b -> c) -> LabelPhantom s a b -> LabelPhantom s a c (#.) :: Coercible c b => q b c -> LabelPhantom s a b -> LabelPhantom s a c (.#) :: Coercible b a => LabelPhantom s b c -> q a b -> LabelPhantom s a c |
type family Labelling s p :: Constraint where ... Source #
Signifies a field name internally
Labelling s (LabelPhantom t) = s ~ t | |
Labelling s p = () |
data Inextensible (xs :: [k]) (h :: k -> Type) Source #
The trivial inextensible data type
Instances
(Functor f, Profunctor p) => Extensible f p (Inextensible :: [k] -> (k -> Type) -> Type) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr Inextensible xs h x :: Constraint Source # pieceAt :: ExtensibleConstr Inextensible xs h x => Membership xs x -> Optic' p f (Inextensible xs h) (h x) Source # | |
type ExtensibleConstr (Inextensible :: [k] -> (k -> Type) -> Type) (xs :: [k]) (h :: k -> Type) (x :: k) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr (Inextensible :: [k] -> (k -> Type) -> Type) (xs :: [k]) (h :: k -> Type) (x :: k) = () |