Safe Haskell | None |
---|---|
Language | Haskell98 |
This module implements the internals of open records and variants.
Synopsis
- newtype Row a = R [LT a]
- data Label (s :: Symbol) = Label
- class KnownSymbol (n :: Symbol)
- data LT a = Symbol :-> a
- type Empty = R '[]
- data HideType where
- type family Extend (l :: Symbol) (a :: k) (r :: Row k) :: Row k where ...
- type family Modify (l :: Symbol) (a :: k) (r :: Row k) :: Row k where ...
- type family Rename (l :: Symbol) (l' :: Symbol) (r :: Row k) :: Row k where ...
- type family (r :: Row k) .\ (l :: Symbol) :: Constraint where ...
- type family (r :: Row k) .! (t :: Symbol) :: k where ...
- type family (r :: Row k) .- (s :: Symbol) :: Row k where ...
- type family (l :: Row k) .+ (r :: Row k) :: Row k where ...
- type family (l :: Row k) .\\ (r :: Row k) :: Row k where ...
- type (.==) (l :: Symbol) (a :: k) = Extend l a Empty
- type family (l :: Row k) .\/ (r :: Row k) where ...
- class Lacks (l :: Symbol) (r :: Row *)
- class (r .! l) ≈ a => HasType l a r
- type family Labels (r :: Row a) where ...
- labels :: forall ρ c s. (IsString s, Forall ρ c) => [s]
- labels' :: forall ρ s. (IsString s, Forall ρ Unconstrained1) => [s]
- class Forall (r :: Row k) (c :: k -> Constraint) where
- class Forall2 (r1 :: Row k) (r2 :: Row k) (c :: k -> Constraint) where
- class Unconstrained1 a
- show' :: (IsString s, Show a) => a -> s
- toKey :: forall s. KnownSymbol s => Label s -> Text
- type (≈) a b = a ~ b
- type WellBehaved ρ = (Forall ρ Unconstrained1, AllUniqueLabels ρ)
- type family AllUniqueLabels (r :: Row k) :: Constraint where ...
- type family Zip (r1 :: Row *) (r2 :: Row *) where ...
- type family Map (f :: a -> b) (r :: Row a) :: Row b where ...
- type family Subset (r1 :: Row k) (r2 :: Row k) :: Constraint where ...
- type Disjoint l r = (WellBehaved l, WellBehaved r, Subset l (l .+ r), Subset r (l .+ r), ((l .+ r) .\\ l) ≈ r, ((l .+ r) .\\ r) ≈ l)
- mapForall :: forall f c ρ. Forall ρ c :- Forall (Map f ρ) (IsA c f)
- freeForall :: forall r c. Forall r c :- Forall r Unconstrained1
- uniqueMap :: forall f ρ. AllUniqueLabels ρ :- AllUniqueLabels (Map f ρ)
- class IsA c f a where
- data As c f a where
- type FoldStep ℓ τ ρ = Inject (ℓ :-> τ) ρ ≈ ((ℓ :-> τ) ': ρ)
Rows
The kind of rows. This type is only used as a datakind. A row is a typelevel entity telling us which symbols are associated with which types.
class KnownSymbol (n :: Symbol) #
This class gives the string associated with a type-level symbol. There are instances of the class for every concrete literal: "hello", etc.
Since: base-4.7.0.0
symbolSing
The kind of elements of rows. Each element is a label and its associated type.
Instances
(KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ, Forall (R ρ) c) => Forall (R ((ℓ :-> τ) ': ρ) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ0 :: Symbol) (τ0 :: k0) (ρ0 :: [LT k0]). (KnownSymbol ℓ0, c τ0) => Label ℓ0 -> f (R ((ℓ0 :-> τ0) ': ρ0)) -> (h τ0, f (R ρ0))) -> (forall (ℓ1 :: Symbol) (τ1 :: k0) (ρ1 :: [LT k0]). (KnownSymbol ℓ1, c τ1, FoldStep ℓ1 τ1 ρ1) => Label ℓ1 -> h τ1 -> g (R ρ1) -> g (R ((ℓ1 :-> τ1) ': ρ1))) -> f (R ((ℓ :-> τ) ': ρ)) -> g (R ((ℓ :-> τ) ': ρ)) Source # metamorph' :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ0 :: Symbol) (τ0 :: k0) (ρ0 :: [LT k0]). (KnownSymbol ℓ0, c τ0) => Label ℓ0 -> f (R ((ℓ0 :-> τ0) ': ρ0)) -> Either (h τ0) (f (R ρ0))) -> (forall (ℓ1 :: Symbol) (τ1 :: k0) (ρ1 :: [LT k0]). (KnownSymbol ℓ1, c τ1, FoldStep ℓ1 τ1 ρ1) => Label ℓ1 -> Either (h τ1) (g (R ρ1)) -> g (R ((ℓ1 :-> τ1) ': ρ1))) -> f (R ((ℓ :-> τ) ': ρ)) -> g (R ((ℓ :-> τ) ': ρ)) Source # | |
Forall (R ([] :: [LT k]) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> (h τ, f (R ρ))) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> h τ -> g (R ρ) -> g (R ((ℓ :-> τ) ': ρ))) -> f (R []) -> g (R []) Source # metamorph' :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> Either (h τ) (f (R ρ))) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> Either (h τ) (g (R ρ)) -> g (R ((ℓ :-> τ) ': ρ))) -> f (R []) -> g (R []) Source # | |
(KnownSymbol ℓ, c τ1, c τ2, Forall2 (R ρ1) (R ρ2) c) => Forall2 (R ((ℓ :-> τ1) ': ρ1) :: Row a) (R ((ℓ :-> τ2) ': ρ2) :: Row a) (c :: a -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph2 :: Proxy f' -> Proxy g' -> (f Empty -> g Empty -> h Empty Empty) -> (forall (ℓ0 :: Symbol) (τ10 :: k) (τ20 :: k) (ρ10 :: [LT k]) (ρ20 :: [LT k]). (KnownSymbol ℓ0, c τ10, c τ20) => Label ℓ0 -> f (R ((ℓ0 :-> τ10) ': ρ10)) -> g (R ((ℓ0 :-> τ20) ': ρ20)) -> ((f' τ10, f (R ρ10)), (g' τ20, g (R ρ20)))) -> (forall (ℓ1 :: Symbol) (τ11 :: k) (τ21 :: k) (ρ11 :: [LT k]) (ρ21 :: [LT k]). (KnownSymbol ℓ1, c τ11, c τ21) => Label ℓ1 -> f' τ11 -> g' τ21 -> h (R ρ11) (R ρ21) -> h (R ((ℓ1 :-> τ11) ': ρ11)) (R ((ℓ1 :-> τ21) ': ρ21))) -> f (R ((ℓ :-> τ1) ': ρ1)) -> g (R ((ℓ :-> τ2) ': ρ2)) -> h (R ((ℓ :-> τ1) ': ρ1)) (R ((ℓ :-> τ2) ': ρ2)) Source # | |
Forall2 (R ([] :: [LT k]) :: Row k) (R ([] :: [LT k]) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph2 :: Proxy f' -> Proxy g' -> (f Empty -> g Empty -> h Empty Empty) -> (forall (ℓ :: Symbol) (τ1 :: k0) (τ2 :: k0) (ρ1 :: [LT k0]) (ρ2 :: [LT k0]). (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f (R ((ℓ :-> τ1) ': ρ1)) -> g (R ((ℓ :-> τ2) ': ρ2)) -> ((f' τ1, f (R ρ1)), (g' τ2, g (R ρ2)))) -> (forall (ℓ :: Symbol) (τ1 :: k0) (τ2 :: k0) (ρ1 :: [LT k0]) (ρ2 :: [LT k0]). (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f' τ1 -> g' τ2 -> h (R ρ1) (R ρ2) -> h (R ((ℓ :-> τ1) ': ρ1)) (R ((ℓ :-> τ2) ': ρ2))) -> f (R []) -> g (R []) -> h (R []) (R []) Source # | |
(KnownSymbol l, Switch (R v) (R r) b) => Switch (R ((l :-> a) ': v)) (R ((l :-> (a -> b)) ': r)) b Source # | |
Switch (R ([] :: [LT *])) (R ([] :: [LT *])) x Source # | |
Elements stored in a Row type are usually hidden.
Row Operations
type family Extend (l :: Symbol) (a :: k) (r :: Row k) :: Row k where ... Source #
Type level Row extension
type family Modify (l :: Symbol) (a :: k) (r :: Row k) :: Row k where ... Source #
Type level Row modification
type family Rename (l :: Symbol) (l' :: Symbol) (r :: Row k) :: Row k where ... Source #
Type level row renaming
type family (r :: Row k) .\ (l :: Symbol) :: Constraint where ... infixl 4 Source #
Does the row lack (i.e. it does not have) the specified label?
type family (r :: Row k) .- (s :: Symbol) :: Row k where ... infixl 6 Source #
Type level Row element removal
type family (l :: Row k) .\\ (r :: Row k) :: Row k where ... infixl 6 Source #
Type level Row difference. That is, l .\\ r
is the row remaining after
removing any matching elements of r
from l
.
type (.==) (l :: Symbol) (a :: k) = Extend l a Empty infix 7 Source #
A type level way to create a singleton Row.
type family (l :: Row k) .\/ (r :: Row k) where ... infixl 6 Source #
The minimum join of the two rows.
class Lacks (l :: Symbol) (r :: Row *) Source #
Alias for .\
. It is a class rather than an alias, so that
it can be partially applied.
Instances
r .\ l => Lacks l r Source # | |
Defined in Data.Row.Internal |
class (r .! l) ≈ a => HasType l a r Source #
Alias for (r .! l) ≈ a
. It is a class rather than an alias, so that
it can be partially applied.
Row Classes
labels :: forall ρ c s. (IsString s, Forall ρ c) => [s] Source #
Return a list of the labels in a row type.
labels' :: forall ρ s. (IsString s, Forall ρ Unconstrained1) => [s] Source #
Return a list of the labels in a row type and is specialized to the Unconstrained1
constraint.
class Forall (r :: Row k) (c :: k -> Constraint) where Source #
Any structure over a row in which every element is similarly constrained can be metamorphized into another structure over the same row.
:: forall (f :: Row k -> *) (g :: Row k -> *) (h :: k -> *). Proxy h | |
-> (f Empty -> g Empty) | The way to transform the empty element |
-> (forall ℓ τ ρ. (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> (h τ, f (R ρ))) | The unfold |
-> (forall ℓ τ ρ. (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> h τ -> g (R ρ) -> g (R ((ℓ :-> τ) ': ρ))) | The fold |
-> f r | The input structure |
-> g r |
A metamorphism is an unfold followed by a fold. This one is for product-like row-types (e.g. Rec).
:: forall (f :: Row k -> *) (g :: Row k -> *) (h :: k -> *). Proxy h | |
-> (f Empty -> g Empty) | The way to transform the empty element |
-> (forall ℓ τ ρ. (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> Either (h τ) (f (R ρ))) | The unfold |
-> (forall ℓ τ ρ. (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> Either (h τ) (g (R ρ)) -> g (R ((ℓ :-> τ) ': ρ))) | The fold |
-> f r | The input structure |
-> g r |
A metamorphism is an unfold followed by a fold. This one is for sum-like row-types (e.g. Var).
Instances
(KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ, Forall (R ρ) c) => Forall (R ((ℓ :-> τ) ': ρ) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ0 :: Symbol) (τ0 :: k0) (ρ0 :: [LT k0]). (KnownSymbol ℓ0, c τ0) => Label ℓ0 -> f (R ((ℓ0 :-> τ0) ': ρ0)) -> (h τ0, f (R ρ0))) -> (forall (ℓ1 :: Symbol) (τ1 :: k0) (ρ1 :: [LT k0]). (KnownSymbol ℓ1, c τ1, FoldStep ℓ1 τ1 ρ1) => Label ℓ1 -> h τ1 -> g (R ρ1) -> g (R ((ℓ1 :-> τ1) ': ρ1))) -> f (R ((ℓ :-> τ) ': ρ)) -> g (R ((ℓ :-> τ) ': ρ)) Source # metamorph' :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ0 :: Symbol) (τ0 :: k0) (ρ0 :: [LT k0]). (KnownSymbol ℓ0, c τ0) => Label ℓ0 -> f (R ((ℓ0 :-> τ0) ': ρ0)) -> Either (h τ0) (f (R ρ0))) -> (forall (ℓ1 :: Symbol) (τ1 :: k0) (ρ1 :: [LT k0]). (KnownSymbol ℓ1, c τ1, FoldStep ℓ1 τ1 ρ1) => Label ℓ1 -> Either (h τ1) (g (R ρ1)) -> g (R ((ℓ1 :-> τ1) ': ρ1))) -> f (R ((ℓ :-> τ) ': ρ)) -> g (R ((ℓ :-> τ) ': ρ)) Source # | |
Forall (R ([] :: [LT k]) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> (h τ, f (R ρ))) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> h τ -> g (R ρ) -> g (R ((ℓ :-> τ) ': ρ))) -> f (R []) -> g (R []) Source # metamorph' :: Proxy h -> (f Empty -> g Empty) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ) => Label ℓ -> f (R ((ℓ :-> τ) ': ρ)) -> Either (h τ) (f (R ρ))) -> (forall (ℓ :: Symbol) (τ :: k0) (ρ :: [LT k0]). (KnownSymbol ℓ, c τ, FoldStep ℓ τ ρ) => Label ℓ -> Either (h τ) (g (R ρ)) -> g (R ((ℓ :-> τ) ': ρ))) -> f (R []) -> g (R []) Source # |
class Forall2 (r1 :: Row k) (r2 :: Row k) (c :: k -> Constraint) where Source #
Any structure over two rows in which every element of both rows satisfies the given constraint can be metamorphized into another structure over both of the rows. TODO: Perhaps it should be over two constraints? But this hasn't seemed necessary in practice.
metamorph2 :: forall (f :: Row k -> *) (g :: Row k -> *) (h :: Row k -> Row k -> *) (f' :: k -> *) (g' :: k -> *). Proxy f' -> Proxy g' -> (f Empty -> g Empty -> h Empty Empty) -> (forall ℓ τ1 τ2 ρ1 ρ2. (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f (R ((ℓ :-> τ1) ': ρ1)) -> g (R ((ℓ :-> τ2) ': ρ2)) -> ((f' τ1, f (R ρ1)), (g' τ2, g (R ρ2)))) -> (forall ℓ τ1 τ2 ρ1 ρ2. (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f' τ1 -> g' τ2 -> h (R ρ1) (R ρ2) -> h (R ((ℓ :-> τ1) ': ρ1)) (R ((ℓ :-> τ2) ': ρ2))) -> f r1 -> g r2 -> h r1 r2 Source #
A metamorphism is a fold followed by an unfold. Here, we fold both of the inputs.
Instances
(KnownSymbol ℓ, c τ1, c τ2, Forall2 (R ρ1) (R ρ2) c) => Forall2 (R ((ℓ :-> τ1) ': ρ1) :: Row a) (R ((ℓ :-> τ2) ': ρ2) :: Row a) (c :: a -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph2 :: Proxy f' -> Proxy g' -> (f Empty -> g Empty -> h Empty Empty) -> (forall (ℓ0 :: Symbol) (τ10 :: k) (τ20 :: k) (ρ10 :: [LT k]) (ρ20 :: [LT k]). (KnownSymbol ℓ0, c τ10, c τ20) => Label ℓ0 -> f (R ((ℓ0 :-> τ10) ': ρ10)) -> g (R ((ℓ0 :-> τ20) ': ρ20)) -> ((f' τ10, f (R ρ10)), (g' τ20, g (R ρ20)))) -> (forall (ℓ1 :: Symbol) (τ11 :: k) (τ21 :: k) (ρ11 :: [LT k]) (ρ21 :: [LT k]). (KnownSymbol ℓ1, c τ11, c τ21) => Label ℓ1 -> f' τ11 -> g' τ21 -> h (R ρ11) (R ρ21) -> h (R ((ℓ1 :-> τ11) ': ρ11)) (R ((ℓ1 :-> τ21) ': ρ21))) -> f (R ((ℓ :-> τ1) ': ρ1)) -> g (R ((ℓ :-> τ2) ': ρ2)) -> h (R ((ℓ :-> τ1) ': ρ1)) (R ((ℓ :-> τ2) ': ρ2)) Source # | |
Forall2 (R ([] :: [LT k]) :: Row k) (R ([] :: [LT k]) :: Row k) (c :: k -> Constraint) Source # | |
Defined in Data.Row.Internal metamorph2 :: Proxy f' -> Proxy g' -> (f Empty -> g Empty -> h Empty Empty) -> (forall (ℓ :: Symbol) (τ1 :: k0) (τ2 :: k0) (ρ1 :: [LT k0]) (ρ2 :: [LT k0]). (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f (R ((ℓ :-> τ1) ': ρ1)) -> g (R ((ℓ :-> τ2) ': ρ2)) -> ((f' τ1, f (R ρ1)), (g' τ2, g (R ρ2)))) -> (forall (ℓ :: Symbol) (τ1 :: k0) (τ2 :: k0) (ρ1 :: [LT k0]) (ρ2 :: [LT k0]). (KnownSymbol ℓ, c τ1, c τ2) => Label ℓ -> f' τ1 -> g' τ2 -> h (R ρ1) (R ρ2) -> h (R ((ℓ :-> τ1) ': ρ1)) (R ((ℓ :-> τ2) ': ρ2))) -> f (R []) -> g (R []) -> h (R []) (R []) Source # |
class Unconstrained1 a Source #
A null constraint of one argument
Instances
Unconstrained1 (a :: k) Source # | |
Defined in Data.Row.Internal |
Helper functions
toKey :: forall s. KnownSymbol s => Label s -> Text Source #
A helper function to turn a Label directly into Text
.
type WellBehaved ρ = (Forall ρ Unconstrained1, AllUniqueLabels ρ) Source #
A convenient way to provide common, easy constraints
type family AllUniqueLabels (r :: Row k) :: Constraint where ... Source #
Are all of the labels in this Row unique?
AllUniqueLabels (R r) = AllUniqueLabelsR r |
type family Zip (r1 :: Row *) (r2 :: Row *) where ... Source #
Zips two rows together to create a Row of the pairs. The two rows must have the same set of labels.
type family Map (f :: a -> b) (r :: Row a) :: Row b where ... Source #
Map a type level function over a Row.
type family Subset (r1 :: Row k) (r2 :: Row k) :: Constraint where ... Source #
Is the first row a subset of the second?
type Disjoint l r = (WellBehaved l, WellBehaved r, Subset l (l .+ r), Subset r (l .+ r), ((l .+ r) .\\ l) ≈ r, ((l .+ r) .\\ r) ≈ l) Source #
A type synonym for disjointness.
mapForall :: forall f c ρ. Forall ρ c :- Forall (Map f ρ) (IsA c f) Source #
This allows us to derive a `Forall (Map f r) ..` from a `Forall r ..`.
freeForall :: forall r c. Forall r c :- Forall r Unconstrained1 Source #
Allow any Forall
over a row-type, be usable for Unconstrained1
.
uniqueMap :: forall f ρ. AllUniqueLabels ρ :- AllUniqueLabels (Map f ρ) Source #
Map preserves uniqueness of labels.
class IsA c f a where Source #
A class to capture the idea of As
so that it can be partially applied in
a context.
Instances
c a => IsA (c :: k2 -> Constraint) (f :: k2 -> k1) (f a :: k1) Source # | |
Defined in Data.Row.Internal |
This data type is used to for its ability to existentially bind a type
variable. Particularly, it says that for the type a
, there exists a t
such that 'a ~ f t' and 'c t' holds.