Skip to content

Commit

Permalink
Add supported for polymorphic nested Rel8ables (#215)
Browse files Browse the repository at this point in the history
```haskell
data Nest t u f = Nest
  { foo :: t f
  , bar :: u f
  }
  deriving (Generic, Rel8able)
``
  • Loading branch information
shane-circuithub committed Nov 8, 2022
1 parent 42e38c7 commit ed4b5bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Rel8/Generic/Rel8able.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type KRel8able = K.Rel8able
-- This is almost 'Data.Type.Equality.==', but we add an extra case.
type (==) :: k -> k -> Bool
type family a == b where
-- This extra case is needed to solve the equation "a == a" (where a is a
-- KRel8able), which occurs when we have polymorphic Rel8ables
-- (e.g., newtype T t f = T { x :: t a })
(a :: KRel8able) == (a :: KRel8able) = 'True

-- This extra case is needed to solve the equation "a == Identity a",
-- which occurs when we have polymorphic Rel8ables
-- (e.g., newtype T a f = T { x :: Column f a })
Expand Down
11 changes: 10 additions & 1 deletion tests/Rel8/Generic/Rel8able/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{-# language DuplicateRecordFields #-}
{-# language FlexibleInstances #-}
{-# language MultiParamTypeClasses #-}
{-# language StandaloneKindSignatures #-}
{-# language TypeFamilies #-}
{-# language UndecidableInstances #-}

Expand Down Expand Up @@ -171,9 +172,17 @@ data NestedTableTestB f = NestedTableTestB
deriving anyclass Rel8able



newtype IdRecord a f = IdRecord { recordId :: Column f a }
deriving stock Generic


instance DBType a => Rel8able (IdRecord a)


type Nest :: KRel8able -> KRel8able -> KRel8able
data Nest t u f = Nest
{ foo :: t f
, bar :: u f
}
deriving stock Generic
deriving anyclass Rel8able

0 comments on commit ed4b5bb

Please sign in to comment.