| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Vinyl.FromTuple
Description
Concise vinyl record construction from tuples up to size 8. An
example record construction using ElField for named fields:
fieldRec (#x =: True, #y =: b) :: FieldRec '[ '("x", Bool), '("y", Char) ]
Synopsis
- type family TupleToRecArgs (f :: u -> Type) t = (r :: (u -> Type, [u])) | r -> t where ...
- type family UncurriedRec (t :: (u -> Type, [u])) = (r :: Type) | r -> u t where ...
- type family UncurriedXRec (t :: (u -> Type, [u])) = (r :: Type) | r -> u t where ...
- class TupleXRec (f :: u -> Type) (t :: [u]) where
- xrecTuple :: XRec f t -> ListToHKDTuple f t
- xrecX :: ListToHKDTuple f t -> XRec f t
- type family ListToHKDTuple (f :: u -> Type) (ts :: [u]) where ...
- ruple :: forall {u} (f :: u -> Type) (ts :: [u]). (IsoXRec f ts, TupleXRec f ts) => Rec f ts -> ListToHKDTuple f ts
- xrec :: forall {u} (f :: u -> Type) (t :: [u]). (IsoXRec f t, TupleXRec f t) => ListToHKDTuple f t -> Rec f t
- class TupleRec (f :: u -> Type) t where
- record :: t -> UncurriedRec (TupleToRecArgs f t)
- fieldRec :: TupleRec ElField t => t -> UncurriedRec (TupleToRecArgs ElField t)
- namedArgs :: forall t (ss :: [(Symbol, Type)]) (rs :: [(Symbol, Type)]). (TupleRec ElField t, ss ~ Snd (TupleToRecArgs ElField t), RecSubset (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) rs (Snd (TupleToRecArgs ElField t)) (RImage rs ss), UncurriedRec (TupleToRecArgs ElField t) ~ Rec ElField ss, RecSubsetFCtx (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) ElField) => t -> Rec ElField rs
- withDefaults :: forall {u} (rs :: [u]) (ss :: [u]) (f :: u -> Type). (RMap rs, RApply rs, ss ⊆ rs, RMap ss, RecApplicative rs) => Rec f rs -> Rec f ss -> Rec f rs
Documentation
type family TupleToRecArgs (f :: u -> Type) t = (r :: (u -> Type, [u])) | r -> t where ... Source #
Convert a tuple of types formed by the application of a common
type constructor to a tuple of the common type constructor and a
list of the types to which it is applied in the original
tuple. E.g. TupleToRecArgs f (f a, f b) ~ (f, [a,b]).
Equations
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c, f d, f e, f z, f g, f h) = '(f, '[a, b, c, d, e, z, g, h]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c, f d, f e, f z, f g) = '(f, '[a, b, c, d, e, z, g]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c, f d, f e, f z) = '(f, '[a, b, c, d, e, z]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c, f d, f e) = '(f, '[a, b, c, d, e]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c, f d) = '(f, '[a, b, c, d]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b, f c) = '(f, '[a, b, c]) | |
| TupleToRecArgs (f :: k -> Type) (f a, f b) = '(f, '[a, b]) | |
| TupleToRecArgs (f :: u -> Type) () = '(f, '[] :: [u]) |
type family UncurriedRec (t :: (u -> Type, [u])) = (r :: Type) | r -> u t where ... Source #
Apply the Rec type constructor to a type-level tuple of its
arguments.
Equations
| UncurriedRec ('(f, ts) :: (u -> Type, [u])) = Rec f ts |
type family UncurriedXRec (t :: (u -> Type, [u])) = (r :: Type) | r -> u t where ... Source #
Apply the XRec type constructor to a type-level tuple of its
arguments.
Equations
| UncurriedXRec ('(f, ts) :: (u -> Type, [u])) = XRec f ts |
class TupleXRec (f :: u -> Type) (t :: [u]) where Source #
Convert between an XRec and an isomorphic tuple.
Methods
xrecTuple :: XRec f t -> ListToHKDTuple f t Source #
Convert an XRec to a tuple. Useful for pattern matching on an
entire record.
xrecX :: ListToHKDTuple f t -> XRec f t Source #
Build an XRec from a tuple.
Instances
| TupleXRec (f :: u -> Type) ('[a, b, c, d, e, z, g, h] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c, d, e, z, g, h] -> ListToHKDTuple f '[a, b, c, d, e, z, g, h] Source # xrecX :: ListToHKDTuple f '[a, b, c, d, e, z, g, h] -> XRec f '[a, b, c, d, e, z, g, h] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b, c, d, e, z, g] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c, d, e, z, g] -> ListToHKDTuple f '[a, b, c, d, e, z, g] Source # xrecX :: ListToHKDTuple f '[a, b, c, d, e, z, g] -> XRec f '[a, b, c, d, e, z, g] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b, c, d, e, z] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c, d, e, z] -> ListToHKDTuple f '[a, b, c, d, e, z] Source # xrecX :: ListToHKDTuple f '[a, b, c, d, e, z] -> XRec f '[a, b, c, d, e, z] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b, c, d, e] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c, d, e] -> ListToHKDTuple f '[a, b, c, d, e] Source # xrecX :: ListToHKDTuple f '[a, b, c, d, e] -> XRec f '[a, b, c, d, e] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b, c, d] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c, d] -> ListToHKDTuple f '[a, b, c, d] Source # xrecX :: ListToHKDTuple f '[a, b, c, d] -> XRec f '[a, b, c, d] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b, c] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b, c] -> ListToHKDTuple f '[a, b, c] Source # xrecX :: ListToHKDTuple f '[a, b, c] -> XRec f '[a, b, c] Source # | |
| TupleXRec (f :: u -> Type) ('[a, b] :: [u]) Source # | |
Defined in Data.Vinyl.FromTuple Methods xrecTuple :: XRec f '[a, b] -> ListToHKDTuple f '[a, b] Source # xrecX :: ListToHKDTuple f '[a, b] -> XRec f '[a, b] Source # | |
type family ListToHKDTuple (f :: u -> Type) (ts :: [u]) where ... Source #
Equations
| ListToHKDTuple (f :: Type -> Type) ('[] :: [Type]) = HKD f () | |
| ListToHKDTuple (f :: k -> Type) ('[a, b] :: [k]) = (HKD f a, HKD f b) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c] :: [k]) = (HKD f a, HKD f b, HKD f c) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c, d] :: [k]) = (HKD f a, HKD f b, HKD f c, HKD f d) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c, d, e] :: [k]) = (HKD f a, HKD f b, HKD f c, HKD f d, HKD f e) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c, d, e, z] :: [k]) = (HKD f a, HKD f b, HKD f c, HKD f d, HKD f e, HKD f z) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c, d, e, z, g] :: [k]) = (HKD f a, HKD f b, HKD f c, HKD f d, HKD f e, HKD f z, HKD f g) | |
| ListToHKDTuple (f :: k -> Type) ('[a, b, c, d, e, z, g, h] :: [k]) = (HKD f a, HKD f b, HKD f c, HKD f d, HKD f e, HKD f z, HKD f g, HKD f h) | |
| ListToHKDTuple (f :: u -> Type) (x :: [u]) = TypeError ('Text "Tuples are only supported up to size 8") :: Type |
ruple :: forall {u} (f :: u -> Type) (ts :: [u]). (IsoXRec f ts, TupleXRec f ts) => Rec f ts -> ListToHKDTuple f ts Source #
xrec :: forall {u} (f :: u -> Type) (t :: [u]). (IsoXRec f t, TupleXRec f t) => ListToHKDTuple f t -> Rec f t Source #
class TupleRec (f :: u -> Type) t where Source #
Build a Rec from a tuple. An example would be building a value
of type Rec f '[a,b] from a tuple of values with type '(f a, f
b).
Methods
record :: t -> UncurriedRec (TupleToRecArgs f t) Source #
Instances
| TupleRec (f :: u -> Type) () Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: () -> UncurriedRec (TupleToRecArgs f ()) Source # | |
| TupleRec (f :: u -> Type) (f a, f b) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b) -> UncurriedRec (TupleToRecArgs f (f a, f b)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c, f d) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c, f d) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c, f d)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c, f d, f e) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c, f d, f e) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c, f d, f e)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c, f d, f e, f z) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c, f d, f e, f z) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c, f d, f e, f z)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c, f d, f e, f z, f g) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c, f d, f e, f z, f g) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c, f d, f e, f z, f g)) Source # | |
| TupleRec (f :: u -> Type) (f a, f b, f c, f d, f e, f z, f g, f h) Source # | |
Defined in Data.Vinyl.FromTuple Methods record :: (f a, f b, f c, f d, f e, f z, f g, f h) -> UncurriedRec (TupleToRecArgs f (f a, f b, f c, f d, f e, f z, f g, f h)) Source # | |
fieldRec :: TupleRec ElField t => t -> UncurriedRec (TupleToRecArgs ElField t) Source #
Build a FieldRec from a tuple of ElField values.
namedArgs :: forall t (ss :: [(Symbol, Type)]) (rs :: [(Symbol, Type)]). (TupleRec ElField t, ss ~ Snd (TupleToRecArgs ElField t), RecSubset (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) rs (Snd (TupleToRecArgs ElField t)) (RImage rs ss), UncurriedRec (TupleToRecArgs ElField t) ~ Rec ElField ss, RecSubsetFCtx (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) ElField) => t -> Rec ElField rs Source #
Build a FieldRec from a tuple and rcast it to another record
type that is a subset of the constructed record. This is useful for
re-ordering fields. For example, namedArgs (#name =: "joe", #age
=: 23) can supply arguments for a function expecting a record of
arguments with its fields in the opposite order.
withDefaults :: forall {u} (rs :: [u]) (ss :: [u]) (f :: u -> Type). (RMap rs, RApply rs, ss ⊆ rs, RMap ss, RecApplicative rs) => Rec f rs -> Rec f ss -> Rec f rs Source #
Override a record with fields from a possibly narrower record. A typical use is to supply default values as the first argument, and overrides for those defaults as the second.