on master help sign in
Document Rel8able
25ed28cOllie Charles
src/Rel8/Schema/Generic.hs+42
@@ -136,6 +136,48 @@ instance (IsSpecialContext context ~ 'False, Labelable context, Nullifiable cont
136 gtoColumns = toUnspecialColumns
136 gtoColumns = toUnspecialColumns
137
137
138
138
139+-- | This type class allows you to define custom 'Table's using higher-kinded
140+-- data types. Higher-kinded data types are data types of the pattern:
141+--
142+-- @
143+-- data MyType f =
144+-- MyType { field1 :: Column f T1 OR HK1 f
145+-- , field2 :: Column f T2 OR HK2 f
146+-- , ...
147+-- , fieldN :: Column f Tn OR HKn f
148+-- }
149+-- @
150+--
151+-- where @Tn@ is any Haskell type, and @HKn@ is any higher-kinded type.
152+--
153+-- That is, higher-kinded data are records where all fields in the record are
154+-- all either of the type @Column f T@ (for any @T@), or are themselves
155+-- higher-kinded data:
156+--
157+-- [Nested]
158+--
159+-- @
160+-- data Nested f =
161+-- Nested { nested1 :: MyType f
162+-- , nested2 :: MyType f
163+-- }
164+-- @
165+--
166+-- The @Rel8able@ type class is used to give us a special mapping operation
167+-- that lets us change the type parameter @f@.
168+--
169+-- [Supplying @Rel8able@ instances]
170+--
171+-- This type class should be derived generically for all table types in your
172+-- project. To do this, enable the @DeriveAnyType@ and @DeriveGeneric@ language
173+-- extensions:
174+--
175+-- @
176+-- \{\-\# LANGUAGE DeriveAnyClass, DeriveGeneric #-\}
177+--
178+-- data MyType f = MyType { fieldA :: Column f T }
179+-- deriving ( GHC.Generics.Generic, Rel8able )
180+-- @
139type Rel8able :: KTable -> Constraint
181type Rel8able :: KTable -> Constraint
140class HTable (GRep t) => Rel8able t where
182class HTable (GRep t) => Rel8able t where
141 type GRep t :: K.HTable
183 type GRep t :: K.HTable