-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A `Projection a b` is a special type of function `a -> b` whereby the resulting `b` is guaranteed to be composed only from columns contained in `a`. We can use this fact to give `ListTable` and `NonEmptyTable` a limit kind of functor. We call this functor `Projectable`, and its `fmap` is called `project`. There's also `Biprojectable` and `biproject` for `EitherTable` and `TheseTable`.
- Loading branch information
1 parent
119c825
commit 032242f
Showing
22 changed files
with
285 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# language DataKinds #-} | ||
{-# language FlexibleContexts #-} | ||
{-# language MultiParamTypeClasses #-} | ||
{-# language StandaloneKindSignatures #-} | ||
{-# language TypeFamilies #-} | ||
|
||
module Rel8.Schema.Field | ||
( Field(..) | ||
, fields | ||
) | ||
where | ||
|
||
-- base | ||
import Data.Functor.Identity ( Identity( Identity ) ) | ||
import Data.Kind ( Type ) | ||
import Prelude | ||
|
||
-- rel8 | ||
import Rel8.Schema.HTable ( HField, htabulate ) | ||
import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) ) | ||
import Rel8.Schema.Kind as K | ||
import Rel8.Schema.Null ( Sql ) | ||
import Rel8.Table | ||
( Table, Columns, Context, fromColumns, toColumns | ||
, FromExprs, fromResult, toResult | ||
, Transpose | ||
) | ||
import Rel8.Table.Transpose ( Transposes ) | ||
import Rel8.Type ( DBType ) | ||
|
||
|
||
-- | A special context used in the construction of 'Rel8.Projection's. | ||
type Field :: Type -> K.Context | ||
newtype Field table a = Field (HField (Columns table) a) | ||
|
||
|
||
instance Sql DBType a => Table (Field table) (Field table a) where | ||
type Columns (Field table a) = HIdentity a | ||
type Context (Field table a) = Field table | ||
type FromExprs (Field table a) = a | ||
type Transpose to (Field table a) = to a | ||
|
||
toColumns = HIdentity | ||
fromColumns (HIdentity a) = a | ||
toResult a = HIdentity (Identity a) | ||
fromResult (HIdentity (Identity a)) = a | ||
|
||
|
||
fields :: Transposes context (Field table) table fields => fields | ||
fields = fromColumns $ htabulate Field |
Oops, something went wrong.