Skip to content

Commit bb02cd1

Browse files
committed
add typefun helping inference by ensuring that Column ~ TableColumn #37
1 parent 9d128fb commit bb02cd1

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/Opaleye/Table.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE FlexibleContexts #-}
2+
{-# LANGUAGE TypeFamilies #-}
23

34
module Opaleye.Table (module Opaleye.Table,
45
-- * Other
@@ -22,6 +23,10 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
2223

2324
import qualified Opaleye.Internal.Schema as S
2425

26+
type family ColumnFromTableColumn a
27+
type instance ColumnFromTableColumn (TM.TableColumn a) = (Column a)
28+
type instance ColumnFromTableColumn (a, b) = (ColumnFromTableColumn a, ColumnFromTableColumn b)
29+
2530
-- | Example type specialization:
2631
--
2732
-- @
@@ -34,7 +39,7 @@ import qualified Opaleye.Internal.Schema as S
3439
-- @
3540
-- queryTable :: Table w (Foo (Column a) (Column b) (Column c)) -> Query (Foo (Column a) (Column b) (Column c))
3641
-- @
37-
queryTable :: (D.Default TM.ColumnMaker columns columns, D.Default TM.TableProjector tableColumns columns) =>
42+
queryTable :: (D.Default TM.ColumnMaker columns columns, D.Default TM.TableProjector tableColumns columns, ColumnFromTableColumn tableColumns ~ columns) =>
3843
Table a tableColumns -> Q.Query columns
3944
queryTable = queryTableExplicit D.def D.def
4045

0 commit comments

Comments
 (0)