packages feed

row-types 0.3.0.0 → 0.3.1.0

raw patch · 5 files changed

+70/−53 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, (ρ Data.Row.Internal..! name) Data.Row.Internal.≈ t) => Data.Row.Records.ToNative (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
- Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Records.FromNative (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
- Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Records.ToNativeExact (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
- Data.Row.Records: instance Data.Row.Records.FromNative GHC.Generics.U1 Data.Row.Internal.Empty
- Data.Row.Records: instance Data.Row.Records.ToNative GHC.Generics.U1 ρ
- Data.Row.Records: instance Data.Row.Records.ToNativeExact GHC.Generics.U1 Data.Row.Internal.Empty
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.FromNative cs ρ => Data.Row.Records.FromNative (GHC.Generics.C1 m cs) ρ
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.FromNative cs ρ => Data.Row.Records.FromNative (GHC.Generics.D1 m cs) ρ
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNative cs ρ => Data.Row.Records.ToNative (GHC.Generics.C1 m cs) ρ
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNative cs ρ => Data.Row.Records.ToNative (GHC.Generics.D1 m cs) ρ
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeExact cs ρ => Data.Row.Records.ToNativeExact (GHC.Generics.C1 m cs) ρ
- Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeExact cs ρ => Data.Row.Records.ToNativeExact (GHC.Generics.D1 m cs) ρ
- Data.Row.Records: instance forall k (l :: k -> *) (ρ :: Data.Row.Internal.Row *) (r :: k -> *). (Data.Row.Records.ToNative l ρ, Data.Row.Records.ToNative r ρ) => Data.Row.Records.ToNative (l GHC.Generics.:*: r) ρ
- Data.Row.Records: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Records.FromNative l ρ₁, Data.Row.Records.FromNative r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂)) => Data.Row.Records.FromNative (l GHC.Generics.:*: r) ρ
- Data.Row.Records: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Records.ToNativeExact l ρ₁, Data.Row.Records.ToNativeExact r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂), Data.Row.Internal.Disjoint ρ₁ ρ₂) => Data.Row.Records.ToNativeExact (l GHC.Generics.:*: r) ρ
- Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, (ρ Data.Row.Internal..! name) Data.Row.Internal.≈ t, Data.Row.Internal.AllUniqueLabels ρ) => Data.Row.Variants.FromNative (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
- Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Variants.FromNativeExact (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
- Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Variants.ToNative (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
- Data.Row.Variants: instance Data.Row.Variants.FromNative GHC.Generics.V1 ρ
- Data.Row.Variants: instance Data.Row.Variants.FromNativeExact GHC.Generics.V1 Data.Row.Internal.Empty
- Data.Row.Variants: instance Data.Row.Variants.ToNative GHC.Generics.V1 Data.Row.Internal.Empty
- Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.FromNative cs ρ => Data.Row.Variants.FromNative (GHC.Generics.D1 m cs) ρ
- Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.FromNativeExact cs ρ => Data.Row.Variants.FromNativeExact (GHC.Generics.D1 m cs) ρ
- Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.ToNative cs ρ => Data.Row.Variants.ToNative (GHC.Generics.D1 m cs) ρ
- Data.Row.Variants: instance forall k (l :: k -> *) (ρ :: Data.Row.Internal.Row *) (r :: k -> *). (Data.Row.Variants.FromNative l ρ, Data.Row.Variants.FromNative r ρ) => Data.Row.Variants.FromNative (l GHC.Generics.:+: r) ρ
- Data.Row.Variants: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Variants.FromNativeExact l ρ₁, Data.Row.Variants.FromNativeExact r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂)) => Data.Row.Variants.FromNativeExact (l GHC.Generics.:+: r) ρ
- Data.Row.Variants: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Variants.ToNative l ρ₁, Data.Row.Variants.ToNative r ρ₂, ρ₂ Data.Row.Internal.≈ (ρ Data.Row.Internal..\\ ρ₁), ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂), Data.Row.Internal.AllUniqueLabels ρ₁, Data.Row.Internal.Forall ρ₂ Data.Row.Internal.Unconstrained1) => Data.Row.Variants.ToNative (l GHC.Generics.:+: r) ρ
+ Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, (ρ Data.Row.Internal..! name) Data.Row.Internal.≈ t) => Data.Row.Records.ToNativeG (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
+ Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Records.FromNativeG (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
+ Data.Row.Records: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Records.ToNativeExactG (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Maybe.Just name) p s l) (GHC.Generics.Rec0 t)) ρ
+ Data.Row.Records: instance Data.Row.Records.FromNativeG GHC.Generics.U1 Data.Row.Internal.Empty
+ Data.Row.Records: instance Data.Row.Records.ToNativeExactG GHC.Generics.U1 Data.Row.Internal.Empty
+ Data.Row.Records: instance Data.Row.Records.ToNativeG GHC.Generics.U1 ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.FromNativeG cs ρ => Data.Row.Records.FromNativeG (GHC.Generics.C1 m cs) ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.FromNativeG cs ρ => Data.Row.Records.FromNativeG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeExactG cs ρ => Data.Row.Records.ToNativeExactG (GHC.Generics.C1 m cs) ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeExactG cs ρ => Data.Row.Records.ToNativeExactG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeG cs ρ => Data.Row.Records.ToNativeG (GHC.Generics.C1 m cs) ρ
+ Data.Row.Records: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Records.ToNativeG cs ρ => Data.Row.Records.ToNativeG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Records: instance forall k (l :: k -> *) (ρ :: Data.Row.Internal.Row *) (r :: k -> *). (Data.Row.Records.ToNativeG l ρ, Data.Row.Records.ToNativeG r ρ) => Data.Row.Records.ToNativeG (l GHC.Generics.:*: r) ρ
+ Data.Row.Records: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Records.FromNativeG l ρ₁, Data.Row.Records.FromNativeG r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂)) => Data.Row.Records.FromNativeG (l GHC.Generics.:*: r) ρ
+ Data.Row.Records: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Records.ToNativeExactG l ρ₁, Data.Row.Records.ToNativeExactG r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂), Data.Row.Internal.Disjoint ρ₁ ρ₂) => Data.Row.Records.ToNativeExactG (l GHC.Generics.:*: r) ρ
+ Data.Row.Records: type FromNative t ρ = (Generic t, FromNativeG (Rep t) ρ)
+ Data.Row.Records: type ToNative t ρ = (Generic t, ToNativeG (Rep t) ρ)
+ Data.Row.Records: type ToNativeExact t ρ = (Generic t, ToNativeExactG (Rep t) ρ)
+ Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, (ρ Data.Row.Internal..! name) Data.Row.Internal.≈ t, Data.Row.Internal.AllUniqueLabels ρ) => Data.Row.Variants.FromNativeG (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
+ Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Variants.FromNativeExactG (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
+ Data.Row.Variants: instance (GHC.TypeLits.KnownSymbol name, ρ Data.Row.Internal.≈ (name Data.Row.Internal..== t)) => Data.Row.Variants.ToNativeG (GHC.Generics.C1 ('GHC.Generics.MetaCons name fixity sels) (GHC.Generics.S1 m (GHC.Generics.Rec0 t))) ρ
+ Data.Row.Variants: instance Data.Row.Variants.FromNativeExactG GHC.Generics.V1 Data.Row.Internal.Empty
+ Data.Row.Variants: instance Data.Row.Variants.FromNativeG GHC.Generics.V1 ρ
+ Data.Row.Variants: instance Data.Row.Variants.ToNativeG GHC.Generics.V1 Data.Row.Internal.Empty
+ Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.FromNativeExactG cs ρ => Data.Row.Variants.FromNativeExactG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.FromNativeG cs ρ => Data.Row.Variants.FromNativeG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Variants: instance forall k (cs :: k -> *) (ρ :: Data.Row.Internal.Row *) (m :: GHC.Generics.Meta). Data.Row.Variants.ToNativeG cs ρ => Data.Row.Variants.ToNativeG (GHC.Generics.D1 m cs) ρ
+ Data.Row.Variants: instance forall k (l :: k -> *) (ρ :: Data.Row.Internal.Row *) (r :: k -> *). (Data.Row.Variants.FromNativeG l ρ, Data.Row.Variants.FromNativeG r ρ) => Data.Row.Variants.FromNativeG (l GHC.Generics.:+: r) ρ
+ Data.Row.Variants: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Variants.FromNativeExactG l ρ₁, Data.Row.Variants.FromNativeExactG r ρ₂, ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂)) => Data.Row.Variants.FromNativeExactG (l GHC.Generics.:+: r) ρ
+ Data.Row.Variants: instance forall k (l :: k -> *) (ρ₁ :: Data.Row.Internal.Row *) (r :: k -> *) (ρ₂ :: Data.Row.Internal.Row *) (ρ :: Data.Row.Internal.Row *). (Data.Row.Variants.ToNativeG l ρ₁, Data.Row.Variants.ToNativeG r ρ₂, ρ₂ Data.Row.Internal.≈ (ρ Data.Row.Internal..\\ ρ₁), ρ Data.Row.Internal.≈ (ρ₁ Data.Row.Internal..+ ρ₂), Data.Row.Internal.AllUniqueLabels ρ₁, Data.Row.Internal.Forall ρ₂ Data.Row.Internal.Unconstrained1) => Data.Row.Variants.ToNativeG (l GHC.Generics.:+: r) ρ
+ Data.Row.Variants: type FromNative t ρ = (Generic t, FromNativeG (Rep t) ρ)
+ Data.Row.Variants: type FromNativeExact t ρ = (Generic t, FromNativeExactG (Rep t) ρ)
+ Data.Row.Variants: type ToNative t ρ = (Generic t, ToNativeG (Rep t) ρ)
- Data.Row.Records: fromNative :: forall t ρ. (Generic t, FromNative (Rep t) ρ) => t -> Rec ρ
+ Data.Row.Records: fromNative :: FromNative t ρ => t -> Rec ρ
- Data.Row.Records: toNative :: forall t ρ. (Generic t, ToNative (Rep t) ρ) => Rec ρ -> t
+ Data.Row.Records: toNative :: ToNative t ρ => Rec ρ -> t
- Data.Row.Records: toNativeExact :: forall t ρ. (Generic t, ToNativeExact (Rep t) ρ) => Rec ρ -> t
+ Data.Row.Records: toNativeExact :: ToNativeExact t ρ => Rec ρ -> t
- Data.Row.Variants: fromNative :: forall t ρ. (Generic t, FromNative (Rep t) ρ) => t -> Var ρ
+ Data.Row.Variants: fromNative :: FromNative t ρ => t -> Var ρ
- Data.Row.Variants: fromNativeExact :: forall t ρ. (Generic t, FromNativeExact (Rep t) ρ) => t -> Var ρ
+ Data.Row.Variants: fromNativeExact :: FromNativeExact t ρ => t -> Var ρ
- Data.Row.Variants: toNative :: forall t ρ. (Generic t, ToNative (Rep t) ρ) => Var ρ -> t
+ Data.Row.Variants: toNative :: ToNative t ρ => Var ρ -> t

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.3.1.0 [2020-01-29]+- Added "native" classes as exports for `Records` and `Variants` (e.g., `ToNative`, `FromNative`)+- Added more example hs files.+ ## 0.3.0.0 [2019-05-28] - Added `HasField` and `AsConstructor` instances (from generic-lens) for `Rec` and `Var` respectively. - Added record-overwrite function `.//`.
Data/Row/Records.hs view
@@ -4,7 +4,7 @@ -- -- This module implements extensible records using closed type famillies. ----- See Examples.hs for examples.+-- See Examples.lhs for examples. -- -- Lists of (label,type) pairs are kept sorted thereby ensuring -- that { x = 0, y = 0 } and { y = 0, x = 0 } have the same type.@@ -43,6 +43,7 @@   -- * Native Conversion   -- $native   , toNative, toNativeExact, fromNative+  , ToNative, ToNativeExact, FromNative   -- * Dynamic Conversion   , toDynamicMap, fromDynamicMap   -- * Row operations@@ -573,84 +574,90 @@  -- | Conversion helper to bring a record back into a Haskell type. Note that the -- native Haskell type must be an instance of 'Generic'.-class ToNative a ρ where+class ToNativeG a ρ where   toNative' :: Rec ρ -> a x -instance ToNative cs ρ => ToNative (G.D1 m cs) ρ where+instance ToNativeG cs ρ => ToNativeG (G.D1 m cs) ρ where   toNative' xs = G.M1 $ toNative' xs -instance ToNative cs ρ => ToNative (G.C1 m cs) ρ where+instance ToNativeG cs ρ => ToNativeG (G.C1 m cs) ρ where   toNative' xs = G.M1 $ toNative' xs -instance ToNative G.U1 ρ where+instance ToNativeG G.U1 ρ where   toNative' _ = G.U1  instance (KnownSymbol name, ρ .! name ≈ t)-    => ToNative (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where+    => ToNativeG (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where   toNative' r = G.M1 $ G.K1 $ r .! (Label @name) -instance (ToNative l ρ, ToNative r ρ)-    => ToNative (l G.:*: r) ρ where+instance (ToNativeG l ρ, ToNativeG r ρ)+    => ToNativeG (l G.:*: r) ρ where   toNative' r = toNative' r G.:*: toNative' r +type ToNative t ρ = (G.Generic t, ToNativeG (G.Rep t) ρ)+ -- | Convert a record to a native Haskell type.-toNative :: forall t ρ. (G.Generic t, ToNative (G.Rep t) ρ) => Rec ρ -> t+toNative :: ToNative t ρ => Rec ρ -> t toNative = G.to . toNative'   -- | Conversion helper to bring a record back into a Haskell type. Note that the -- native Haskell type must be an instance of 'Generic'.-class ToNativeExact a ρ where+class ToNativeExactG a ρ where   toNativeExact' :: Rec ρ -> a x -instance ToNativeExact cs ρ => ToNativeExact (G.D1 m cs) ρ where+instance ToNativeExactG cs ρ => ToNativeExactG (G.D1 m cs) ρ where   toNativeExact' xs = G.M1 $ toNativeExact' xs -instance ToNativeExact cs ρ => ToNativeExact (G.C1 m cs) ρ where+instance ToNativeExactG cs ρ => ToNativeExactG (G.C1 m cs) ρ where   toNativeExact' xs = G.M1 $ toNativeExact' xs -instance ToNativeExact G.U1 Empty where+instance ToNativeExactG G.U1 Empty where   toNativeExact' _ = G.U1  instance (KnownSymbol name, ρ ≈ name .== t)-    => ToNativeExact (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where+    => ToNativeExactG (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where   toNativeExact' r = G.M1 $ G.K1 $ r .! (Label @name) -instance (ToNativeExact l ρ₁, ToNativeExact r ρ₂, ρ ≈ ρ₁ .+ ρ₂, Disjoint ρ₁ ρ₂)-    => ToNativeExact (l G.:*: r) ρ where+instance (ToNativeExactG l ρ₁, ToNativeExactG r ρ₂, ρ ≈ ρ₁ .+ ρ₂, Disjoint ρ₁ ρ₂)+    => ToNativeExactG (l G.:*: r) ρ where   toNativeExact' r = toNativeExact' r1 G.:*: toNativeExact' r2     where       (r1 :: Rec ρ₁) :+ (r2 :: Rec ρ₂) = r +type ToNativeExact t ρ = (G.Generic t, ToNativeExactG (G.Rep t) ρ)+ -- | Convert a record to an exactly matching native Haskell type.-toNativeExact :: forall t ρ. (G.Generic t, ToNativeExact (G.Rep t) ρ) => Rec ρ -> t+toNativeExact :: ToNativeExact t ρ => Rec ρ -> t toNativeExact = G.to . toNativeExact'   -- | Conversion helper to turn a Haskell record into a row-types extensible -- record. Note that the native Haskell type must be an instance of 'Generic'.-class FromNative a ρ where+class FromNativeG a ρ where   fromNative' :: a x -> Rec ρ -instance FromNative cs ρ => FromNative (G.D1 m cs) ρ where+instance FromNativeG cs ρ => FromNativeG (G.D1 m cs) ρ where   fromNative' (G.M1 xs) = fromNative' xs -instance FromNative cs ρ => FromNative (G.C1 m cs) ρ where+instance FromNativeG cs ρ => FromNativeG (G.C1 m cs) ρ where   fromNative' (G.M1 xs) = fromNative' xs -instance FromNative G.U1 Empty where+instance FromNativeG G.U1 Empty where   fromNative' G.U1 = empty  instance (KnownSymbol name, ρ ≈ name .== t)-    => FromNative (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where+    => FromNativeG (G.S1 ('G.MetaSel ('Just name) p s l) (G.Rec0 t)) ρ where   fromNative' (G.M1 (G.K1 x)) =  (Label @name) .== x -instance (FromNative l ρ₁, FromNative r ρ₂, ρ ≈ ρ₁ .+ ρ₂)-    => FromNative (l G.:*: r) ρ where+instance (FromNativeG l ρ₁, FromNativeG r ρ₂, ρ ≈ ρ₁ .+ ρ₂)+    => FromNativeG (l G.:*: r) ρ where   fromNative' (x G.:*: y) = fromNative' @l @ρ₁ x .+ fromNative' @r @ρ₂ y +type FromNative t ρ = (G.Generic t, FromNativeG (G.Rep t) ρ)+ -- | Convert a Haskell record to a row-types Rec.-fromNative :: forall t ρ. (G.Generic t, FromNative (G.Rep t) ρ) => t -> Rec ρ+fromNative :: FromNative t ρ => t -> Rec ρ fromNative = fromNative' . G.from  
Data/Row/Variants.hs view
@@ -28,6 +28,7 @@   -- * Native Conversion   -- $native   , toNative, fromNative, fromNativeExact+  , ToNative, FromNative, FromNativeExact   -- * Row operations   -- ** Map   , Map, map, map', transform, transform'@@ -425,83 +426,89 @@  -- | Conversion helper to bring a variant back into a Haskell type. Note that the -- native Haskell type must be an instance of 'Generic'.-class ToNative a ρ where+class ToNativeG a ρ where   toNative' :: Var ρ -> a x -instance ToNative cs ρ => ToNative (G.D1 m cs) ρ where+instance ToNativeG cs ρ => ToNativeG (G.D1 m cs) ρ where   toNative' = G.M1 . toNative' -instance ToNative G.V1 Empty where+instance ToNativeG G.V1 Empty where   toNative' = impossible  instance (KnownSymbol name, ρ ≈ name .== t)-    => ToNative (G.C1 ('G.MetaCons name fixity sels)+    => ToNativeG (G.C1 ('G.MetaCons name fixity sels)                 (G.S1 m (G.Rec0 t))) ρ where   toNative' = G.M1 . G.M1 . G.K1 . snd . unSingleton -instance ( ToNative l ρ₁, ToNative r ρ₂, ρ₂ ≈ ρ .\\ ρ₁, ρ ≈ ρ₁ .+ ρ₂+instance ( ToNativeG l ρ₁, ToNativeG r ρ₂, ρ₂ ≈ ρ .\\ ρ₁, ρ ≈ ρ₁ .+ ρ₂          , AllUniqueLabels ρ₁, Forall ρ₂ Unconstrained1)-    => ToNative (l G.:+: r) ρ where+    => ToNativeG (l G.:+: r) ρ where   toNative' v = case multiTrial @ρ₁ @ρ v of     Left  v' -> G.L1 $ toNative' @_ @ρ₁ v'     Right v' -> G.R1 $ toNative' @_ @ρ₂ v' +type ToNative t ρ = (G.Generic t, ToNativeG (G.Rep t) ρ)+ -- | Convert a variant to a native Haskell type.-toNative :: forall t ρ. (G.Generic t, ToNative (G.Rep t) ρ) => Var ρ -> t+toNative :: ToNative t ρ => Var ρ -> t toNative = G.to . toNative'  -- | Conversion helper to turn a Haskell variant into a row-types extensible -- variant. Note that the native Haskell type must be an instance of 'Generic'.-class FromNative a ρ where+class FromNativeG a ρ where   fromNative' :: a x -> Var ρ -instance FromNative cs ρ => FromNative (G.D1 m cs) ρ where+instance FromNativeG cs ρ => FromNativeG (G.D1 m cs) ρ where   fromNative' (G.M1 v) = fromNative' v -instance FromNative G.V1 ρ where+instance FromNativeG G.V1 ρ where   fromNative' = \ case  instance (KnownSymbol name, ρ .! name ≈ t, AllUniqueLabels ρ)-    => FromNative (G.C1 ('G.MetaCons name fixity sels)+    => FromNativeG (G.C1 ('G.MetaCons name fixity sels)                   (G.S1 m (G.Rec0 t))) ρ where   fromNative' (G.M1 (G.M1 (G.K1 x))) = IsJust (Label @name) x -instance (FromNative l ρ, FromNative r ρ)-    => FromNative (l G.:+: r) ρ where+instance (FromNativeG l ρ, FromNativeG r ρ)+    => FromNativeG (l G.:+: r) ρ where   -- Ideally, we would use 'diversify' here instead of 'unsafeCoerce', but it   -- makes the constraints really hairy.   fromNative' (G.L1 x) = unsafeCoerce $ fromNative' @l @ρ x   fromNative' (G.R1 y) = unsafeCoerce $ fromNative' @r @ρ y +type FromNative t ρ = (G.Generic t, FromNativeG (G.Rep t) ρ)+ -- | Convert a Haskell record to a row-types Var.-fromNative :: forall t ρ. (G.Generic t, FromNative (G.Rep t) ρ) => t -> Var ρ+fromNative :: FromNative t ρ => t -> Var ρ fromNative = fromNative' . G.from  -- | Conversion helper to turn a Haskell variant into a row-types extensible -- variant. Note that the native Haskell type must be an instance of 'Generic'.-class FromNativeExact a ρ where+class FromNativeExactG a ρ where   fromNativeExact' :: a x -> Var ρ -instance FromNativeExact cs ρ => FromNativeExact (G.D1 m cs) ρ where+instance FromNativeExactG cs ρ => FromNativeExactG (G.D1 m cs) ρ where   fromNativeExact' (G.M1 v) = fromNativeExact' v -instance FromNativeExact G.V1 Empty where+instance FromNativeExactG G.V1 Empty where   fromNativeExact' = \ case  instance (KnownSymbol name, ρ ≈ name .== t)-    => FromNativeExact (G.C1 ('G.MetaCons name fixity sels)+    => FromNativeExactG (G.C1 ('G.MetaCons name fixity sels)                        (G.S1 m (G.Rec0 t))) ρ where   fromNativeExact' (G.M1 (G.M1 (G.K1 x))) = IsJust (Label @name) x -instance (FromNativeExact l ρ₁, FromNativeExact r ρ₂, ρ ≈ ρ₁ .+ ρ₂)-    => FromNativeExact (l G.:+: r) ρ where+instance (FromNativeExactG l ρ₁, FromNativeExactG r ρ₂, ρ ≈ ρ₁ .+ ρ₂)+    => FromNativeExactG (l G.:+: r) ρ where   -- Ideally, we would use 'diversify' here instead of 'unsafeCoerce', but it   -- makes the constraints really hairy.   fromNativeExact' (G.L1 x) = unsafeCoerce $ fromNativeExact' @l @ρ₁ x   fromNativeExact' (G.R1 y) = unsafeCoerce $ fromNativeExact' @r @ρ₂ y +type FromNativeExact t ρ = (G.Generic t, FromNativeExactG (G.Rep t) ρ)+ -- | Convert a Haskell record to a row-types Var.-fromNativeExact :: forall t ρ. (G.Generic t, FromNativeExact (G.Rep t) ρ) => t -> Var ρ+fromNativeExact :: FromNativeExact t ρ => t -> Var ρ fromNativeExact = fromNativeExact' . G.from  
README.md view
@@ -7,16 +7,15 @@ Row-types is a library of open records and variants for Haskell using closed type families and type literals (among other things...). See [examples/Examples.lhs](https://raw.githubusercontent.com/target/row-types/master/examples/Examples.lhs)-for an overview of how this library can be used.--Available on [Hackage](https://hackage.haskell.org/package/row-types)+for a literate Haskell file that functions as an overview of how this library can be used,+and check out [the website](https://target.github.io/row-types/) for further examples. +Available on [Hackage](https://hackage.haskell.org/package/row-types).  This work is a branch from CTRex [1,2] with other inspiration from data-diverse [3]. My thanks to the authors and contributors of those libraries! -[1] https://wiki.haskell.org/CTRex -[2] https://hackage.haskell.org/package/CTRex/docs/Data-OpenRecords.html-+[1] https://wiki.haskell.org/CTRex \+[2] https://hackage.haskell.org/package/CTRex/docs/Data-OpenRecords.html \ [3] https://hackage.haskell.org/package/data-diverse
row-types.cabal view
@@ -1,5 +1,5 @@ Name:                row-types-Version:             0.3.0.0+Version:             0.3.1.0 License:             MIT License-file:        LICENSE Author:              Daniel Winograd-Cort, Matthew Farkas-Dyck