Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Haskell singly-linked lists are very powerful. This module provides functionality for type-level lists, heterogeneous lists and type aligned lists.
Synopsis
- data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where
- (*:) :: f x -> f y -> NP f '[x, y]
- one :: f x -> NP f '[x]
- type family Join xs ys where ...
- disjoin :: forall xs ys expr. SListI xs => NP expr (Join xs ys) -> (NP expr xs, NP expr ys)
- class Additional expr where
- data Path (p :: k -> k -> Type) (x :: k) (y :: k) :: forall k. (k -> k -> Type) -> k -> k -> Type where
- type family Elem x xs where ...
- type family In x xs :: Constraint where ...
- type family Length (xs :: [k]) :: Nat where ...
Heterogeneous List
data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where #
An n-ary product.
The product is parameterized by a type constructor f
and
indexed by a type-level list xs
. The length of the list
determines the number of elements in the product, and if the
i
-th element of the list is of type x
, then the i
-th
element of the product is of type f x
.
The constructor names are chosen to resemble the names of the list constructors.
Two common instantiations of f
are the identity functor I
and the constant functor K
. For I
, the product becomes a
heterogeneous list, where the type-level list describes the
types of its components. For
, the product becomes a
homogeneous list, where the contents of the type-level list are
ignored, but its length still specifies the number of elements.K
a
In the context of the SOP approach to generic programming, an n-ary product describes the structure of the arguments of a single data constructor.
Examples:
I 'x' :* I True :* Nil :: NP I '[ Char, Bool ] K 0 :* K 1 :* Nil :: NP (K Int) '[ Char, Bool ] Just 'x' :* Nothing :* Nil :: NP Maybe '[ Char, Bool ]
Nil :: forall k (a :: k -> Type) (b :: [k]). NP a ([] :: [k]) | |
(:*) :: forall k (a :: k -> Type) (b :: [k]) (x :: k) (xs :: [k]). a x -> NP a xs -> NP a (x ': xs) infixr 5 |
Instances
(Has tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsQualified tab col (NP (Aliased (Expression (Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullType]))) => IsQualified tab col (NP (Expression (Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsQualified tab col (NP (Aliased (Expression Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has tab (Join lat from) row, Has col row ty, tys ~ (ty ': ([] :: [NullType]))) => IsQualified tab col (NP (Expression Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(Has rel rels cols, Has col cols ty, bys ~ ((,) rel col ': ([] :: [(Symbol, Symbol)]))) => IsQualified rel col (NP (By rels) bys) Source # | |
HTrans (NP :: (k1 -> Type) -> [k1] -> Type) (NP :: (k2 -> Type) -> [k2] -> Type) | |
HSequence (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hsequence' :: (SListIN NP xs, Applicative f) => NP (f :.: g) xs -> f (NP g xs) # hctraverse' :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # htraverse' :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # | |
HTraverse_ (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hctraverse_ :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NP f xs -> g () # htraverse_ :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NP f xs -> g () # | |
HCollapse (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
HAp (NP :: (k -> Type) -> [k] -> Type) | |
HPure (NP :: (k -> Type) -> [k] -> Type) | |
(KnownSymbol alias, tys ~ ((alias ::: ty) ': ([] :: [(Symbol, k)]))) => Aliasable alias (expression ty) (NP (Aliased expression) tys) Source # | |
Additional (NP expr :: [a] -> Type) Source # | |
aliases ~ (alias ': ([] :: [Symbol])) => IsLabel alias (NP Alias aliases) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
(HasUnique tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsLabel col (NP (Aliased (Expression (Grouped bys) lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join lat from) row, Has col row ty, GroupedBy tab col bys, tys ~ (ty ': ([] :: [NullType]))) => IsLabel col (NP (Expression (Grouped bys) lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression (Grouped bys) lat with db params from) tys # | |
(HasUnique tab (Join lat from) row, Has col row ty, columns ~ ((col ::: ty) ': ([] :: [(Symbol, NullType)]))) => IsLabel col (NP (Aliased (Expression Ungrouped lat with db params from)) columns) Source # | |
Defined in Squeal.PostgreSQL.Expression | |
(HasUnique tab (Join lat from) row, Has col row ty, tys ~ (ty ': ([] :: [NullType]))) => IsLabel col (NP (Expression Ungrouped lat with db params from) tys) Source # | |
Defined in Squeal.PostgreSQL.Expression fromLabel :: NP (Expression Ungrouped lat with db params from) tys # | |
(HasUnique rel rels cols, Has col cols ty, bys ~ ((,) rel col ': ([] :: [(Symbol, Symbol)]))) => IsLabel col (NP (By rels) bys) Source # | |
Defined in Squeal.PostgreSQL.Query.Table | |
labels ~ (label ': ([] :: [Symbol])) => IsPGlabel label (NP PGlabel labels) Source # | |
All (Compose Eq f) xs => Eq (NP f xs) | |
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NP f xs) | |
All (Compose Show f) xs => Show (NP f xs) | |
All (Compose Semigroup f) xs => Semigroup (NP f xs) | Since: sop-core-0.4.0.0 |
(All (Compose Monoid f) xs, All (Compose Semigroup f) xs) => Monoid (NP f xs) | Since: sop-core-0.4.0.0 |
All (Compose NFData f) xs => NFData (NP f xs) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.NP | |
All KnownSymbol aliases => RenderSQL (NP Alias aliases) Source # | |
Defined in Squeal.PostgreSQL.Type.Alias | |
All KnownSymbol labels => RenderSQL (NP PGlabel labels) Source # | |
Defined in Squeal.PostgreSQL.Type.Schema | |
type Same (NP :: (k1 -> Type) -> [k1] -> Type) | |
type UnProd (NP :: (k -> Type) -> [k] -> Type) | |
type Prod (NP :: (k -> Type) -> [k] -> Type) | |
type CollapseTo (NP :: (k -> Type) -> [k] -> Type) a | |
Defined in Data.SOP.NP | |
type SListIN (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
type AllN (NP :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) | |
Defined in Data.SOP.NP | |
type AllZipN (NP :: (k -> Type) -> [k] -> Type) (c :: a -> b -> Constraint) | |
Defined in Data.SOP.NP |
type family Join xs ys where ... Source #
Join
is simply promoted ++
and is used in JOIN
s in
FromClause
s.
disjoin :: forall xs ys expr. SListI xs => NP expr (Join xs ys) -> (NP expr xs, NP expr ys) Source #
class Additional expr where Source #
The Additional
class is for appending
type-level list parameterized constructors such as NP
,
Selection
, and FromClause
.
Instances
Additional (NP expr :: [a] -> Type) Source # | |
Additional (FromClause lat with db params :: FromType -> Type) Source # | |
Defined in Squeal.PostgreSQL.Query.From also :: FromClause lat with db params ys -> FromClause lat with db params xs -> FromClause lat with db params (Join xs ys) Source # | |
Additional (Selection grp lat with db params from :: RowType -> Type) Source # | |
Path
data Path (p :: k -> k -> Type) (x :: k) (y :: k) :: forall k. (k -> k -> Type) -> k -> k -> Type where #
A Path
with steps in p
is a singly linked list of
"type-aligned" constructions of p
.
>>>
:{
let path :: Path (->) String Int path = length :>> (\x -> x^2) :>> Done in qfold path "hello" :} 25
Done :: forall k (p :: k -> k -> Type) (x :: k) (y :: k). Path p x x | |
(:>>) :: forall k (p :: k -> k -> Type) (x :: k) (y :: k) (y1 :: k). p x y1 -> Path p y1 y -> Path p x y infixr 7 |
Instances
QFunctor (Path :: (k -> k -> Type) -> k -> k -> Type) | |
Defined in Control.Category.Free | |
QPointed (Path :: (k -> k -> Type) -> k -> k -> Type) | |
Defined in Control.Category.Free | |
QMonad (Path :: (k -> k -> Type) -> k -> k -> Type) | |
CFree (Path :: (k -> k -> Type) -> k -> k -> Type) | |
Defined in Control.Category.Free | |
QFoldable (Path :: (k -> k -> Type) -> k -> k -> Type) | |
Defined in Control.Category.Free qfoldMap :: Category q => (forall (x1 :: k0) (y1 :: k0). p x1 y1 -> q x1 y1) -> Path p x y -> q x y # qfold :: Category q => Path q x y -> q x y # qfoldr :: (forall (x1 :: k0) (y1 :: k0) (z1 :: k1). p x1 y1 -> q y1 z1 -> q x1 z1) -> q y z -> Path p x y -> q x z # qfoldl :: (forall (x1 :: k1) (y1 :: k0) (z1 :: k0). q x1 y1 -> p y1 z1 -> q x1 z1) -> q x y -> Path p y z -> q x z # qtoMonoid :: Monoid m => (forall (x1 :: k0) (y1 :: k0). p x1 y1 -> m) -> Path p x y -> m # qtoList :: (forall (x1 :: k0) (y1 :: k0). p x1 y1 -> a) -> Path p x y -> [a] # qtraverse_ :: (Applicative m, Category q) => (forall (x1 :: k0) (y1 :: k0). p x1 y1 -> m (q x1 y1)) -> Path p x y -> m (q x y) # | |
QTraversable (Path :: (k -> k -> Type) -> k -> k -> Type) | |
Defined in Control.Category.Free qtraverse :: Applicative m => (forall (x1 :: k0) (y1 :: k0). p x1 y1 -> m (q x1 y1)) -> Path p x y -> m (Path q x y) # | |
Category (Path p :: k -> k -> Type) | |
(KnownSymbol cte, with1 ~ ((cte ::: common) ': with)) => Aliasable cte (statement with db params common) (Path (CommonTableExpression statement db params) with with1) Source # | |
Defined in Squeal.PostgreSQL.Query.With | |
(forall (x1 :: k) (y1 :: k). Show (p x1 y1)) => Show (Path p x y) | |
x ~ y => Semigroup (Path p x y) | |
x ~ y => Monoid (Path p x y) | |
Type Level List
type family In x xs :: Constraint where ... Source #
In x xs
is a constraint that proves that x
is in xs
.