polytropos-core 0.1.0.3 → 0.1.2.0
raw patch · API changes only · 9 files changed · show whitespace changes · browse polytropos-core-0.1.2.0
+1671/−61 lines, 9 filesdep ~basePVP: major bump suggested
Dependency ranges changed: base
API changes (from Hackage documentation)
26 removed, 196 added, 15 changed
API removals or changes: PVP suggests a major version bump
- Polytropos: instance GHC.Classes.Eq Polytropos.REC
- Polytropos: instance GHC.Classes.Eq Polytropos.REC_F
- Polytropos: instance GHC.Classes.Eq Polytropos.REC_UPD
- Polytropos: instance GHC.Classes.Eq Polytropos.REC_UPD_F
- Polytropos: instance GHC.Classes.Eq Polytropos.VAR
- Polytropos: instance GHC.Show.Show Polytropos.REC
- Polytropos: instance GHC.Show.Show Polytropos.REC_F
- Polytropos: instance GHC.Show.Show Polytropos.REC_UPD
- Polytropos: instance GHC.Show.Show Polytropos.REC_UPD_F
- Polytropos: instance GHC.Show.Show Polytropos.VAR
- Polytropos.Core: instance (l GHC.Types.~ l') => GHC.OverloadedLabels.IsLabel l (Polytropos.Core.Field l')
- Polytropos.Core: instance GHC.Show.Show (Polytropos.Core.ProxyRowFlavour r)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). (Polytropos.Core.RowEq 'Polytropos.Core.ProductRowHKDT row, Polytropos.Core.AllFields 'Polytropos.Core.ProductRowHKDT row GHC.Classes.Ord) => GHC.Classes.Ord (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). (Polytropos.Core.RowEq 'Polytropos.Core.ProductRowT row, Polytropos.Core.AllFields 'Polytropos.Core.ProductRowT row GHC.Classes.Ord) => GHC.Classes.Ord (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEq 'Polytropos.Core.ProductRowHKDT row => GHC.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEq 'Polytropos.Core.ProductRowT row => GHC.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEqSum 'Polytropos.Core.SumRowHKDT row => GHC.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowHKDT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEqSum 'Polytropos.Core.SumRowT row => GHC.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShow 'Polytropos.Core.ProductRowHKDT row => GHC.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShow 'Polytropos.Core.ProductRowT row => GHC.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShowSum 'Polytropos.Core.SumRowHKDT row => GHC.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowHKDT row a)
- Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShowSum 'Polytropos.Core.SumRowT row => GHC.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowT row a)
- Polytropos.RowMorph: instance forall k1 (frameIn :: k1) k2 (opIn :: k2) k3 (opOut :: k3) k4 (frameOut :: k4). GHC.Classes.Eq (Polytropos.RowMorph.FramePlan frameIn opIn opOut frameOut)
- Polytropos.RowMorph: instance forall k1 (frameIn :: k1) k2 (opIn :: k2) k3 (opOut :: k3) k4 (frameOut :: k4). GHC.Show.Show (Polytropos.RowMorph.FramePlan frameIn opIn opOut frameOut)
- Polytropos.RowMorph: instance forall k1 (r1 :: k1) k2 (r2 :: k2). GHC.Classes.Eq (Polytropos.RowMorph.RowMorph r1 r2)
- Polytropos.RowMorph: instance forall k1 (r1 :: k1) k2 (r2 :: k2). GHC.Show.Show (Polytropos.RowMorph.RowMorph r1 r2)
+ Polytropos: OpenTailSlot :: String -> String -> SlotIndex
+ Polytropos: RowLayoutDescriptor :: [(String, Int)] -> [(String, s)] -> Maybe String -> RowLayoutDescriptorOf s
+ Polytropos: StaticSlot :: Int -> SlotIndex
+ Polytropos: [rldKnownSlots] :: RowLayoutDescriptorOf s -> [(String, Int)]
+ Polytropos: [rldKnownSorts] :: RowLayoutDescriptorOf s -> [(String, s)]
+ Polytropos: [rldOpenTail] :: RowLayoutDescriptorOf s -> Maybe String
+ Polytropos: buildRowLayoutDescriptor :: [String] -> Maybe String -> RowLayoutDescriptor
+ Polytropos: class ConstructorIndex (n :: kn) (row :: k)
+ Polytropos: class FieldIndex (n :: kn) (row :: k) (a :: ka)
+ Polytropos: constructorIndex :: ConstructorIndex n row => Word
+ Polytropos: data RowLayoutDescriptorOf s
+ Polytropos: data SlotIndex
+ Polytropos: fieldIndex :: FieldIndex n row a => Int
+ Polytropos: hfromRecord :: forall {k} (row :: Row) (a :: k). Record row -> RowRep Identity 'ProductRowT row a
+ Polytropos: hfromVariant :: forall {k} (row :: SumRow) (a :: k). Variant row -> RowRep Identity 'SumRowT row a
+ Polytropos: htoRecord :: forall {k} (row :: Row) (a :: k). RowRep Identity 'ProductRowT row a -> Record row
+ Polytropos: htoVariant :: forall {k} (row :: SumRow) (a :: k). RowRep Identity 'SumRowT row a -> Variant row
+ Polytropos: infix 4 :-
+ Polytropos: instance (r GHC.Internal.Types.~ '[n 'Polytropos.Core.:= a], f GHC.Internal.Types.~ GHC.Internal.Data.Functor.Identity.Identity, tag GHC.Internal.Types.~ 'Polytropos.Core.ProductRowT) => GHC.Internal.OverloadedLabels.IsLabel n (a -> Polytropos.Core.RowRep f tag r ())
+ Polytropos: instance GHC.Internal.Classes.Eq Polytropos.REC
+ Polytropos: instance GHC.Internal.Classes.Eq Polytropos.REC_F
+ Polytropos: instance GHC.Internal.Classes.Eq Polytropos.REC_UPD
+ Polytropos: instance GHC.Internal.Classes.Eq Polytropos.REC_UPD_F
+ Polytropos: instance GHC.Internal.Classes.Eq Polytropos.VAR
+ Polytropos: instance GHC.Internal.Show.Show Polytropos.REC
+ Polytropos: instance GHC.Internal.Show.Show Polytropos.REC_F
+ Polytropos: instance GHC.Internal.Show.Show Polytropos.REC_UPD
+ Polytropos: instance GHC.Internal.Show.Show Polytropos.REC_UPD_F
+ Polytropos: instance GHC.Internal.Show.Show Polytropos.VAR
+ Polytropos: resolveRowSlot :: RowLayoutDescriptorOf s -> String -> SlotIndex
+ Polytropos: type (:-) = SubRow :: k1 -> k2 -> Constraint
+ Polytropos: type RowLayoutDescriptor = RowLayoutDescriptorOf String
+ Polytropos.Core: infix 4 :-
+ Polytropos.Core: instance (l GHC.Internal.Types.~ l') => GHC.Internal.OverloadedLabels.IsLabel l (Polytropos.Core.Field l')
+ Polytropos.Core: instance GHC.Internal.Show.Show (Polytropos.Core.ProxyRowFlavour r)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). (Polytropos.Core.RowEq 'Polytropos.Core.ProductRowHKDT row, Polytropos.Core.AllFields 'Polytropos.Core.ProductRowHKDT row GHC.Internal.Classes.Ord) => GHC.Internal.Classes.Ord (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). (Polytropos.Core.RowEq 'Polytropos.Core.ProductRowT row, Polytropos.Core.AllFields 'Polytropos.Core.ProductRowT row GHC.Internal.Classes.Ord) => GHC.Internal.Classes.Ord (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEq 'Polytropos.Core.ProductRowHKDT row => GHC.Internal.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEq 'Polytropos.Core.ProductRowT row => GHC.Internal.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEqSum 'Polytropos.Core.SumRowHKDT row => GHC.Internal.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowHKDT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowEqSum 'Polytropos.Core.SumRowT row => GHC.Internal.Classes.Eq (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShow 'Polytropos.Core.ProductRowHKDT row => GHC.Internal.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowHKDT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShow 'Polytropos.Core.ProductRowT row => GHC.Internal.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.ProductRowT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShowSum 'Polytropos.Core.SumRowHKDT row => GHC.Internal.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowHKDT row a)
+ Polytropos.Core: instance forall k1 k2 (row :: k1) (f :: * -> *) (a :: k2). Polytropos.Core.RowShowSum 'Polytropos.Core.SumRowT row => GHC.Internal.Show.Show (Polytropos.Core.RowRep f 'Polytropos.Core.SumRowT row a)
+ Polytropos.Core: type (:-) = SubRow :: k1 -> k2 -> Constraint
+ Polytropos.Core.SOP: Fn :: (f a -> g a) -> (-.->) (f :: k -> Type) (g :: k -> Type) (a :: k)
+ Polytropos.Core.SOP: I :: a -> I a
+ Polytropos.Core.SOP: [apFn] :: (-.->) (f :: k -> Type) (g :: k -> Type) (a :: k) -> f a -> g a
+ Polytropos.Core.SOP: [unI] :: I a -> a
+ Polytropos.Core.SOP: apInjs :: forall {k1} {k} (f :: Type -> Type) (row :: k1) (a :: k). RowRep f 'ProductRowT row a -> [RowRep f 'SumRowT row a]
+ Polytropos.Core.SOP: class RowFlavour r => HCMap (r :: RowType)
+ Polytropos.Core.SOP: class ReifyFieldNames (r :: k)
+ Polytropos.Core.SOP: class Top (a :: k)
+ Polytropos.Core.SOP: comp :: forall {k} {k1} f (g :: k1 -> k) (a :: k1). f (g a) -> (f :.: g) a
+ Polytropos.Core.SOP: hap :: forall {k1} {k} (f :: Type -> Type) (g :: Type -> Type) (row :: k1) (a :: k). RowRep (f -.-> g) 'ProductRowT row a -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a
+ Polytropos.Core.SOP: hapProduct :: forall {k1} {k} (f :: Type -> Type) (g :: Type -> Type) (row :: k1) (a :: k). RowRep (f -.-> g) 'ProductRowT row a -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a
+ Polytropos.Core.SOP: hapSum :: forall {k1} {k} (f :: Type -> Type) (g :: Type -> Type) (row :: k1) (a :: k). RowRep (f -.-> g) 'ProductRowT row a -> RowRep f 'SumRowT row a -> RowRep g 'SumRowT row a
+ Polytropos.Core.SOP: hcfoldMap :: forall {k1} {k} c (row :: k1) m f (a :: k). (AllFields 'ProductRowT row c, Monoid m) => (forall x. c x => f x -> m) -> RowRep f 'ProductRowT row a -> m
+ Polytropos.Core.SOP: hcfoldMapSum :: forall {k1} {k} c (row :: k1) m f (a :: k). (AllFields 'SumRowT row c, Monoid m) => (forall x. c x => f x -> m) -> RowRep f 'SumRowT row a -> m
+ Polytropos.Core.SOP: hcfoldMap_ :: forall {k1} {k} c (row :: k1) m f (a :: k) proxy. (AllFields 'ProductRowT row c, Monoid m) => proxy c -> (forall x. c x => f x -> m) -> RowRep f 'ProductRowT row a -> m
+ Polytropos.Core.SOP: hcliftA :: forall {k1} {k} c (row :: k1) f g (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a
+ Polytropos.Core.SOP: hcliftA2 :: forall {k1} {k} c (row :: k1) f g h (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x -> h x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a
+ Polytropos.Core.SOP: hcliftA2Sum :: forall {k1} {k} c (row :: k1) f g h (a :: k). AllFields 'SumRowT row c => (forall x. c x => f x -> g x -> h x) -> RowRep f 'SumRowT row a -> RowRep g 'SumRowT row a -> Maybe (RowRep h 'SumRowT row a)
+ Polytropos.Core.SOP: hcliftA2_ :: forall {k1} {k} c (row :: k1) f g h (a :: k) proxy. AllFields 'ProductRowT row c => proxy c -> (forall x. c x => f x -> g x -> h x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a
+ Polytropos.Core.SOP: hcliftA3 :: forall {k1} {k} c (row :: k1) f g h i (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x -> h x -> i x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a -> RowRep i 'ProductRowT row a
+ Polytropos.Core.SOP: hcliftA3_ :: forall {k1} {k} c (row :: k1) f g h i (a :: k) proxy. AllFields 'ProductRowT row c => proxy c -> (forall x. c x => f x -> g x -> h x -> i x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a -> RowRep i 'ProductRowT row a
+ Polytropos.Core.SOP: hcliftA_ :: forall {k1} {k} c (row :: k1) f g (a :: k) proxy. AllFields 'ProductRowT row c => proxy c -> (forall x. c x => f x -> g x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a
+ Polytropos.Core.SOP: hcmap :: forall {k1} {k} c (r :: RowType) (row :: k1) f g (a :: k). (HCMap r, AllFields r row c) => (forall x. c x => f x -> g x) -> RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hcmapImpl :: forall {k1} {k} c (row :: k1) f g (a :: k). (HCMap r, AllFields r row c) => (forall x. c x => f x -> g x) -> RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hcmapProduct :: forall {k1} {k} c (row :: k1) f g (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a
+ Polytropos.Core.SOP: hcmapSum :: forall {k1} {k} c (row :: k1) f g (a :: k). AllFields 'SumRowT row c => (forall x. c x => f x -> g x) -> RowRep f 'SumRowT row a -> RowRep g 'SumRowT row a
+ Polytropos.Core.SOP: hcmap_ :: forall {k1} {k} c (r :: RowType) (row :: k1) f g (a :: k) proxy. (HCMap r, AllFields r row c) => proxy c -> (forall x. c x => f x -> g x) -> RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hcoerce :: forall {k1} {k} (f :: Type -> Type) (g :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). (forall x. () => Coercible (f x) (g x)) => RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hcollapse :: forall {k1} {k} a (r :: RowType) (row :: k1) (x :: k). RowRep (Const a :: Type -> Type) r row x -> [a]
+ Polytropos.Core.SOP: hcollapseFold :: forall {k1} {k} a (r :: RowType) (row :: k1) (x :: k). RowRep (Const a :: Type -> Type) r row x -> [a]
+ Polytropos.Core.SOP: hcpure :: forall {k1} {k} c (row :: k1) f (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x) -> RowRep f 'ProductRowT row a
+ Polytropos.Core.SOP: hcpure_ :: forall {k1} {k} c (row :: k1) f (a :: k) proxy. AllFields 'ProductRowT row c => proxy c -> (forall x. c x => f x) -> RowRep f 'ProductRowT row a
+ Polytropos.Core.SOP: hctraverse :: forall {k1} {k} c (row :: k1) m f g (a :: k). (AllFields 'ProductRowT row c, Applicative m) => (forall x. c x => f x -> m (g x)) -> RowRep f 'ProductRowT row a -> m (RowRep g 'ProductRowT row a)
+ Polytropos.Core.SOP: hctraverse_ :: forall {k1} {k} c (row :: k1) m f g (a :: k) proxy. (AllFields 'ProductRowT row c, Applicative m) => proxy c -> (forall x. c x => f x -> m (g x)) -> RowRep f 'ProductRowT row a -> m (RowRep g 'ProductRowT row a)
+ Polytropos.Core.SOP: hczipWith :: forall {k1} {k} c (row :: k1) f g h (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x -> h x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a
+ Polytropos.Core.SOP: hczipWith3 :: forall {k1} {k} c (row :: k1) f g h i (a :: k). AllFields 'ProductRowT row c => (forall x. c x => f x -> g x -> h x -> i x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a -> RowRep i 'ProductRowT row a
+ Polytropos.Core.SOP: hdeunit :: forall {k1} {k} (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). RowRep f r row () -> RowRep f r row a
+ Polytropos.Core.SOP: helim :: forall {k1} {k} (f :: Type -> Type) b (row :: k1) (a :: k). RowRep (f -.-> (Const b :: Type -> Type)) 'ProductRowT row a -> RowRep f 'SumRowT row a -> b
+ Polytropos.Core.SOP: hexpand :: forall {k1} {k} (row :: k1) (f :: Type -> Type) (a :: k). ReifyFieldNames row => RowRep f 'SumRowT row a -> RowRep (Compose Maybe f) 'ProductRowT row a
+ Polytropos.Core.SOP: hexpandArity :: forall {k1} {k} (f :: Type -> Type) (row :: k1) (a :: k). Int -> RowRep f 'SumRowT row a -> RowRep (Compose Maybe f) 'ProductRowT row a
+ Polytropos.Core.SOP: hfieldNames :: forall {k1} {k} (row :: k1) (a :: k). ReifyFieldNames row => RowRep (Const String :: Type -> Type) 'ProductRowT row a
+ Polytropos.Core.SOP: hfoldMap :: forall {k1} {k} m f (r :: RowType) (row :: k1) (a :: k). Monoid m => (forall x. () => f x -> m) -> RowRep f r row a -> m
+ Polytropos.Core.SOP: hfromI :: forall {k1} {k} (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). (forall x. () => Coercible (Identity x) (f x)) => RowRep Identity r row a -> RowRep f r row a
+ Polytropos.Core.SOP: hhead :: forall {k1} {k} f (row :: k1) (a :: k). RowRep f 'ProductRowT row a -> f (Any :: Type)
+ Polytropos.Core.SOP: hindex :: forall {k1} {k} (f :: Type -> Type) (row :: k1) (a :: k). RowRep f 'SumRowT row a -> Int
+ Polytropos.Core.SOP: hliftA :: forall {k1} {k} f g (r :: RowType) (row :: k1) (a :: k). (forall x. () => f x -> g x) -> RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hliftA2 :: forall {k1} {k} f g h (row :: k1) (a :: k). (forall x. () => f x -> g x -> h x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a
+ Polytropos.Core.SOP: hliftA2Sum :: forall {k1} {k} f g h (row :: k1) (a :: k). (forall x. () => f x -> g x -> h x) -> RowRep f 'SumRowT row a -> RowRep g 'SumRowT row a -> Maybe (RowRep h 'SumRowT row a)
+ Polytropos.Core.SOP: hliftA3 :: forall {k1} {k} f g h i (row :: k1) (a :: k). (forall x. () => f x -> g x -> h x -> i x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a -> RowRep i 'ProductRowT row a
+ Polytropos.Core.SOP: hmap :: forall {k1} {k} f g (r :: RowType) (row :: k1) (a :: k). (forall x. () => f x -> g x) -> RowRep f r row a -> RowRep g r row a
+ Polytropos.Core.SOP: hproduct :: forall {k1} {k} (f :: Type -> Type) (row :: k1) (a :: k) (g :: Type -> Type). RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep (Product f g) 'ProductRowT row a
+ Polytropos.Core.SOP: hpure :: forall {k1} {k} (row :: k1) f (a :: k). AllFields 'ProductRowT row (Top :: Type -> Constraint) => (forall x. () => f x) -> RowRep f 'ProductRowT row a
+ Polytropos.Core.SOP: hpureArity :: forall {k1} {k} f (row :: k1) (a :: k). Int -> (forall x. () => f x) -> RowRep f 'ProductRowT row a
+ Polytropos.Core.SOP: hpureFromNames :: forall {k1} {k} (row :: k1) f (a :: k). ReifyFieldNames row => (forall x. () => f x) -> RowRep f 'ProductRowT row a
+ Polytropos.Core.SOP: hsequence :: forall {k1} {k} m (r :: RowType) (row :: k1) (a :: k). Applicative m => RowRep m r row a -> m (RowRep Identity r row a)
+ Polytropos.Core.SOP: hsequence' :: forall {k1} {k} m (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). Applicative m => RowRep (Compose m f) r row a -> m (RowRep f r row a)
+ Polytropos.Core.SOP: htoI :: forall {k1} {k} (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). (forall x. () => Coercible (f x) (Identity x)) => RowRep f r row a -> RowRep Identity r row a
+ Polytropos.Core.SOP: htraverse :: forall {k1} {k} m f g (r :: RowType) (row :: k1) (a :: k). Applicative m => (forall x. () => f x -> m (g x)) -> RowRep f r row a -> m (RowRep g r row a)
+ Polytropos.Core.SOP: hunit :: forall {k1} {k} (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k). RowRep f r row a -> RowRep f r row ()
+ Polytropos.Core.SOP: hunzip :: forall {k1} {k} (f :: Type -> Type) (g :: Type -> Type) (row :: k1) (a :: k). RowRep (Product f g) 'ProductRowT row a -> (RowRep f 'ProductRowT row a, RowRep g 'ProductRowT row a)
+ Polytropos.Core.SOP: hzipWith :: forall {k1} {k} f g h (row :: k1) (a :: k). (forall x. () => f x -> g x -> h x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a
+ Polytropos.Core.SOP: hzipWith3 :: forall {k1} {k} f g h i (row :: k1) (a :: k). (forall x. () => f x -> g x -> h x -> i x) -> RowRep f 'ProductRowT row a -> RowRep g 'ProductRowT row a -> RowRep h 'ProductRowT row a -> RowRep i 'ProductRowT row a
+ Polytropos.Core.SOP: infixr 1 -.->
+ Polytropos.Core.SOP: infixr 8 :.:
+ Polytropos.Core.SOP: injections :: forall {k1} {k} (row :: k1) (f :: Type -> Type) (a :: k). ReifyFieldNames row => RowRep (f -.-> (Const (RowRep f 'SumRowT row a) :: Type -> Type)) 'ProductRowT row a
+ Polytropos.Core.SOP: injectionsArity :: forall {k1} {k} (row :: k1) (f :: Type -> Type) (a :: k). Int -> RowRep (f -.-> (Const (RowRep f 'SumRowT row a) :: Type -> Type)) 'ProductRowT row a
+ Polytropos.Core.SOP: instance (GHC.Internal.TypeLits.KnownSymbol n, Polytropos.Core.SOP.ReifyFieldNames rest) => Polytropos.Core.SOP.ReifyFieldNames (n : rest)
+ Polytropos.Core.SOP: instance GHC.Internal.Classes.Eq a => GHC.Internal.Classes.Eq (Polytropos.Core.SOP.I a)
+ Polytropos.Core.SOP: instance GHC.Internal.Classes.Ord a => GHC.Internal.Classes.Ord (Polytropos.Core.SOP.I a)
+ Polytropos.Core.SOP: instance GHC.Internal.Read.Read a => GHC.Internal.Read.Read (Polytropos.Core.SOP.I a)
+ Polytropos.Core.SOP: instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Polytropos.Core.SOP.I a)
+ Polytropos.Core.SOP: instance Polytropos.Core.SOP.HCMap 'Polytropos.Core.ProductRowT
+ Polytropos.Core.SOP: instance Polytropos.Core.SOP.HCMap 'Polytropos.Core.SumRowT
+ Polytropos.Core.SOP: instance Polytropos.Core.SOP.ReifyFieldNames '[]
+ Polytropos.Core.SOP: instance forall b (n :: GHC.Internal.Types.Symbol) (rest :: [Polytropos.Core.Pair GHC.Internal.Types.Symbol b]) (a :: b). (GHC.Internal.TypeLits.KnownSymbol n, Polytropos.Core.SOP.ReifyFieldNames rest) => Polytropos.Core.SOP.ReifyFieldNames ((n 'Polytropos.Core.:= a) : rest)
+ Polytropos.Core.SOP: instance forall k (a :: k). Polytropos.Core.SOP.Top a
+ Polytropos.Core.SOP: newtype ( (f :: k -> Type) -.-> (g :: k -> Type) ) (a :: k)
+ Polytropos.Core.SOP: newtype I a
+ Polytropos.Core.SOP: reifyFieldNames :: ReifyFieldNames r => [String]
+ Polytropos.Core.SOP: type (:.:) = Compose :: k -> Type -> k1 -> k -> k1 -> Type
+ Polytropos.Core.SOP: type K = Const :: Type -> k -> Type
+ Polytropos.Core.SOP: unComp :: forall {k} {k1} f (g :: k1 -> k) (a :: k1). (f :.: g) a -> f (g a)
+ Polytropos.Core.SOP: unK :: forall {k} a (b :: k). K a b -> a
+ Polytropos.MergeMorph: (/-/) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (g :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpDiff r1 r2 rOut => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: (//>) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpOverrideR r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: (//~) :: forall (r1 :: Row) (r2 :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpReplace r1 r2 r1 => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT r1 ()
+ Polytropos.MergeMorph: (<+>) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpDisjoint r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: (<//) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpOverrideL r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: (\^/) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpSymDiff r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: (|<) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (g :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpRestrict r1 r2 rOut => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: MergeMorph :: PrimArray Int -> MergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row)
+ Polytropos.MergeMorph: OpDiff :: MergeOp
+ Polytropos.MergeMorph: OpDisjoint :: MergeOp
+ Polytropos.MergeMorph: OpOverrideL :: MergeOp
+ Polytropos.MergeMorph: OpOverrideR :: MergeOp
+ Polytropos.MergeMorph: OpReplace :: MergeOp
+ Polytropos.MergeMorph: OpRestrict :: MergeOp
+ Polytropos.MergeMorph: OpSymDiff :: MergeOp
+ Polytropos.MergeMorph: [unMergeMorph] :: MergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row) -> PrimArray Int
+ Polytropos.MergeMorph: class KnownMergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row) | op r1 r2 -> rOut
+ Polytropos.MergeMorph: data MergeOp
+ Polytropos.MergeMorph: executeMergeMorph :: forall (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). MergeMorph op r1 r2 rOut -> RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.MergeMorph: infixl 6 //~
+ Polytropos.MergeMorph: infixl 7 \^/
+ Polytropos.MergeMorph: instance GHC.Internal.Classes.Eq (Polytropos.MergeMorph.MergeMorph op r1 r2 rOut)
+ Polytropos.MergeMorph: instance GHC.Internal.Classes.Eq Polytropos.MergeMorph.MergeOp
+ Polytropos.MergeMorph: instance GHC.Internal.Classes.Ord Polytropos.MergeMorph.MergeOp
+ Polytropos.MergeMorph: instance GHC.Internal.Show.Show (Polytropos.MergeMorph.MergeMorph op r1 r2 rOut)
+ Polytropos.MergeMorph: instance GHC.Internal.Show.Show Polytropos.MergeMorph.MergeOp
+ Polytropos.MergeMorph: mergeMorph :: KnownMergeMorph op r1 r2 rOut => MergeMorph op r1 r2 rOut
+ Polytropos.MergeMorph: newtype MergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row)
+ Polytropos.MergeMorph: unsafeMkMergeMorph :: forall (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row). [Int] -> MergeMorph op r1 r2 rOut
+ Polytropos.MergeMorph: unsafeMkMergeMorph# :: forall (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row). Int# -> Addr# -> MergeMorph op r1 r2 rOut
+ Polytropos.Record: (/-/) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (g :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpDiff r1 r2 rOut => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: (//>) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpOverrideR r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: (//~) :: forall (r1 :: Row) (r2 :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpReplace r1 r2 r1 => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT r1 ()
+ Polytropos.Record: (<+>) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpDisjoint r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: (<//) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpOverrideL r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: (\^/) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpSymDiff r1 r2 rOut => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: (|<) :: forall (r1 :: Row) (r2 :: Row) (rOut :: Row) (f :: Type -> Type) (g :: Type -> Type) (tag1 :: RowType) (tag2 :: RowType). KnownMergeMorph 'OpRestrict r1 r2 rOut => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f 'ProductRowT rOut ()
+ Polytropos.Record: RowRep :: Rep f a -> RowRep (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k)
+ Polytropos.Record: data RowRep (f :: Type -> Type) (r :: RowType) (row :: k1) (a :: k)
+ Polytropos.Record: emptyRecord :: Record ('[] :: [Pair Symbol Type])
+ Polytropos.Record: emptyRecordF :: forall (f :: Type -> Type). RecordF f ('[] :: [Pair Symbol Type])
+ Polytropos.Record: infixl 6 //~
+ Polytropos.Record: infixl 7 \^/
+ Polytropos.Record: type Record (r :: Row) = RowRep Identity 'ProductRowT r ()
+ Polytropos.Record: type RecordF (f :: Type -> Type) (r :: ProductRow f) = RowRep f 'ProductRowHKDT r ()
+ Polytropos.RowMorph: OpenTailSlot :: String -> String -> SlotIndex
+ Polytropos.RowMorph: RowLayoutDescriptor :: [(String, Int)] -> [(String, s)] -> Maybe String -> RowLayoutDescriptorOf s
+ Polytropos.RowMorph: StaticSlot :: Int -> SlotIndex
+ Polytropos.RowMorph: [rldKnownSlots] :: RowLayoutDescriptorOf s -> [(String, Int)]
+ Polytropos.RowMorph: [rldKnownSorts] :: RowLayoutDescriptorOf s -> [(String, s)]
+ Polytropos.RowMorph: [rldOpenTail] :: RowLayoutDescriptorOf s -> Maybe String
+ Polytropos.RowMorph: buildRowLayoutDescriptor :: [String] -> Maybe String -> RowLayoutDescriptor
+ Polytropos.RowMorph: data RowLayoutDescriptorOf s
+ Polytropos.RowMorph: data SlotIndex
+ Polytropos.RowMorph: instance GHC.Internal.Classes.Eq Polytropos.RowMorph.SlotIndex
+ Polytropos.RowMorph: instance GHC.Internal.Classes.Eq s => GHC.Internal.Classes.Eq (Polytropos.RowMorph.RowLayoutDescriptorOf s)
+ Polytropos.RowMorph: instance GHC.Internal.Classes.Ord Polytropos.RowMorph.SlotIndex
+ Polytropos.RowMorph: instance GHC.Internal.Generics.Generic (Polytropos.RowMorph.RowLayoutDescriptorOf s)
+ Polytropos.RowMorph: instance GHC.Internal.Generics.Generic Polytropos.RowMorph.SlotIndex
+ Polytropos.RowMorph: instance GHC.Internal.Show.Show Polytropos.RowMorph.SlotIndex
+ Polytropos.RowMorph: instance GHC.Internal.Show.Show s => GHC.Internal.Show.Show (Polytropos.RowMorph.RowLayoutDescriptorOf s)
+ Polytropos.RowMorph: instance forall k1 (frameIn :: k1) k2 (opIn :: k2) k3 (opOut :: k3) k4 (frameOut :: k4). GHC.Internal.Classes.Eq (Polytropos.RowMorph.FramePlan frameIn opIn opOut frameOut)
+ Polytropos.RowMorph: instance forall k1 (frameIn :: k1) k2 (opIn :: k2) k3 (opOut :: k3) k4 (frameOut :: k4). GHC.Internal.Show.Show (Polytropos.RowMorph.FramePlan frameIn opIn opOut frameOut)
+ Polytropos.RowMorph: instance forall k1 (r1 :: k1) k2 (r2 :: k2). GHC.Internal.Classes.Eq (Polytropos.RowMorph.RowMorph r1 r2)
+ Polytropos.RowMorph: instance forall k1 (r1 :: k1) k2 (r2 :: k2). GHC.Internal.Show.Show (Polytropos.RowMorph.RowMorph r1 r2)
+ Polytropos.RowMorph: resolveRowSlot :: RowLayoutDescriptorOf s -> String -> SlotIndex
+ Polytropos.RowMorph: type RowLayoutDescriptor = RowLayoutDescriptorOf String
- Polytropos: FramePlan :: {-# UNPACK #-} !Int -> !RowMorph opIn frameIn -> !RowMorph frameIn frameOut -> !RowMorph opOut frameOut -> FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4)
+ Polytropos: FramePlan :: Int -> RowMorph opIn frameIn -> RowMorph frameIn frameOut -> RowMorph opOut frameOut -> FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4)
- Polytropos: [fpBaseScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph frameIn frameOut
+ Polytropos: [fpBaseScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph frameIn frameOut
- Polytropos: [fpGatherIn] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph opIn frameIn
+ Polytropos: [fpGatherIn] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph opIn frameIn
- Polytropos: [fpOpScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph opOut frameOut
+ Polytropos: [fpOpScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph opOut frameOut
- Polytropos: [fpOutSize] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> {-# UNPACK #-} !Int
+ Polytropos: [fpOutSize] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> Int
- Polytropos: class HasField (x :: k) r a | x r -> a
+ Polytropos: class HasField (x :: k) (r :: TYPE r_rep) (a :: TYPE a_rep) | x r -> a
- Polytropos: injectVariant :: forall (n :: Symbol) (s :: SumRow) (fs :: Row). ConstructorIndex n s => Field n -> Record fs -> Variant s
+ Polytropos: injectVariant :: forall (n :: Symbol) (s :: SumRow). ConstructorIndex n s => Field n -> Record (ConstructorPayload n s) -> Variant s
- Polytropos: injectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f) (fs :: ProductRow f). ConstructorIndex n s => Field n -> RecordF f fs -> VariantF f s
+ Polytropos: injectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f). ConstructorIndex n s => Field n -> RecordF f (ConstructorPayloadHKD f n s) -> VariantF f s
- Polytropos.Core: MRep :: {-# UNPACK #-} !Word -> !SmallMutableArray s (f (Any :: Type)) -> MRep s (f :: Type -> Type) (a :: k)
+ Polytropos.Core: MRep :: Word -> SmallMutableArray s (f (Any :: Type)) -> MRep s (f :: Type -> Type) (a :: k)
- Polytropos.Core: Rep :: {-# UNPACK #-} !Word -> !SmallArray (f (Any :: Type)) -> Rep (f :: Type -> Type) (a :: k)
+ Polytropos.Core: Rep :: Word -> SmallArray (f (Any :: Type)) -> Rep (f :: Type -> Type) (a :: k)
- Polytropos.RowMorph: FramePlan :: {-# UNPACK #-} !Int -> !RowMorph opIn frameIn -> !RowMorph frameIn frameOut -> !RowMorph opOut frameOut -> FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4)
+ Polytropos.RowMorph: FramePlan :: Int -> RowMorph opIn frameIn -> RowMorph frameIn frameOut -> RowMorph opOut frameOut -> FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4)
- Polytropos.RowMorph: [fpBaseScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph frameIn frameOut
+ Polytropos.RowMorph: [fpBaseScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph frameIn frameOut
- Polytropos.RowMorph: [fpGatherIn] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph opIn frameIn
+ Polytropos.RowMorph: [fpGatherIn] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph opIn frameIn
- Polytropos.RowMorph: [fpOpScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> !RowMorph opOut frameOut
+ Polytropos.RowMorph: [fpOpScatter] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> RowMorph opOut frameOut
- Polytropos.RowMorph: [fpOutSize] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> {-# UNPACK #-} !Int
+ Polytropos.RowMorph: [fpOutSize] :: FramePlan (frameIn :: k1) (opIn :: k2) (opOut :: k3) (frameOut :: k4) -> Int
Files
- CHANGELOG.md +10/−0
- polytropos-core.cabal +6/−2
- src/Polytropos.hs +57/−12
- src/Polytropos/Core.hs +42/−34
- src/Polytropos/Core/SOP.hs +1027/−0
- src/Polytropos/MergeMorph.hs +148/−0
- src/Polytropos/Record.hs +25/−0
- src/Polytropos/RowMorph.hs +63/−12
- test/Main.hs +293/−1 · folded
CHANGELOG.md view
@@ -1,5 +1,15 @@ # Changelog for polytropos-core +## 0.1.2.0 — 2026-11-22++- Breaking soundness fix: constrain `injectVariant` and `injectVariantF` payload rows strictly to `Record (ConstructorPayload n s)` and `RecordF f (ConstructorPayloadHKD f n s)`.+- Propagate `ConstructorPayload` constraints to optics and profunctor adapters.+- Consolidate intermediate development revisions into 0.1.2.0.++## 0.1.1.0 — 2026-11-18++- MergeMorph skew Boolean algebra: reified row operations `(<+>)`, `(//>)`, `(//~)`, `(|<)`, `(/-/)`, `(\^/)`.+ ## 0.1.0.3 — 2026-11-03 - Reified Row Morphisms (`RowMorph`): static permutation arrays and `KnownRowMorph` TcPlugin solver for compile-time peephole route fusion.
polytropos-core.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: polytropos-core-version: 0.1.0.3+version: 0.1.2.0 synopsis: Row-polymorphic / open ADTs: rows, generic representation, evidence description: Core engine and consumer surface of <https://hackage.haskell.org/package/polytropos polytropos>:@@ -48,10 +48,13 @@ import: warnings exposed-modules: Polytropos , Polytropos.Core+ , Polytropos.Core.SOP , Polytropos.RowMorph+ , Polytropos.MergeMorph+ , Polytropos.Record hs-source-dirs: src default-language: GHC2021- build-depends: base >= 4.18 && < 4.23+ build-depends: base >= 4.18 && < 4.24 , primitive >= 0.9 && < 0.10 test-suite polytropos-core-test@@ -60,6 +63,7 @@ main-is: Main.hs hs-source-dirs: test default-language: GHC2021+ ghc-options: -threaded -rtsopts "-with-rtsopts=-N" build-depends: base , polytropos-core , primitive
src/Polytropos.hs view
@@ -11,6 +11,7 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE Trustworthy #-}+{-# OPTIONS_GHC -Wno-orphans #-} {-| Module : Polytropos@@ -193,7 +194,7 @@ Polytropos provides first-class support for functorial / Higher-Kinded Data rows, where every field type @a@ is parameterized by an outer type constructor @f a@-(e.g. 'Maybe' for partial forms or 'Identity' for validated domain entities):+(e.g. 'Maybe' for partial forms or 't:Identity' for validated domain entities): > {-# LANGUAGE DataKinds #-} >@@ -248,6 +249,7 @@ , type ConstructorPayloadHKD -- * Sub-row & Sub-variant operations , SubRow(..)+ , type (:-) , SubSum(..) , projectRecord , projectRecordF@@ -268,6 +270,12 @@ , FrameWire(..) , executeFrameScatter , executeFrameRecord+ -- * 2LTT Static Layout Descriptors+ , SlotIndex(..)+ , RowLayoutDescriptorOf(..)+ , RowLayoutDescriptor+ , buildRowLayoutDescriptor+ , resolveRowSlot -- * Elimination & Peeling , peel , peelF@@ -284,6 +292,8 @@ -- * Re-exports , Pair(..) , HasField(..)+ , FieldIndex(..)+ , ConstructorIndex(..) , RowEq(..) , RowShow(..) , RowFlavour(..)@@ -321,14 +331,25 @@ , czipWithRecord , cmapRecordF , cfoldMapRecordF+ -- * Sums of Products (SOP) Interface+ , module Polytropos.Core.SOP+ , htoRecord+ , hfromRecord+ , htoVariant+ , hfromVariant+ -- * Row Merge Operations & Skew Boolean Algebra+ , module Polytropos.MergeMorph ) where import Polytropos.Core+import Polytropos.Core.SOP+import Polytropos.MergeMorph import Polytropos.RowMorph import Data.Functor.Identity (Identity(..)) import Data.Kind (Type) import Data.Primitive.SmallArray (copySmallArray, indexSmallArray, newSmallArray, runSmallArray, sizeofSmallArray, thawSmallArray, writeSmallArray) import GHC.Exts (Any)+import GHC.OverloadedLabels (IsLabel(..)) import GHC.Records (HasField(..)) import GHC.TypeLits (Symbol) import Unsafe.Coerce (unsafeCoerce)@@ -533,6 +554,10 @@ pure m in RowRep (Rep 0 v') +-- | Overloaded label instance allowing @#foo x@ to construct a single-field record @Record '["foo" ':= typeof x]@.+instance (r ~ '[n ':= a], f ~ Identity, tag ~ ProductRowT) => IsLabel n (a -> RowRep f tag r ()) where+ fromLabel a = insertField (Field @n) a emptyRecord+ -- | Compute the payload product row of a constructor @n@ in a sum row @s@. type family ConstructorPayload (n :: Symbol) (s :: SumRow) :: Row where ConstructorPayload n ((n ':= fs) ': rest) = fs@@ -544,8 +569,8 @@ ConstructorPayloadHKD f n ((m ':= fs) ': rest) = ConstructorPayloadHKD f n rest -- | Inject an HKD record into an HKD variant for a specific constructor.-injectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f) (fs :: ProductRow f).- ConstructorIndex n s => Field n -> RecordF f fs -> VariantF f s+injectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f).+ ConstructorIndex n s => Field n -> RecordF f (ConstructorPayloadHKD f n s) -> VariantF f s injectVariantF _ (RowRep (Rep _ v)) = RowRep (Rep (constructorIndex @_ @n @s) v) @@ -568,7 +593,7 @@ where VariantF f r = injectVariantF f r -- | Inject a record of fields into a variant for a specific constructor in \(\mathcal{O}(1)\) time.-injectVariant :: forall n s fs. ConstructorIndex n s => Field n -> Record fs -> Variant s+injectVariant :: forall n s. ConstructorIndex n s => Field n -> Record (ConstructorPayload n s) -> Variant s injectVariant _ (RowRep (Rep _ v)) = RowRep (Rep (constructorIndex @_ @n @s) v) @@ -704,20 +729,20 @@ -------------------------------------------------------------------------------} -- | Contravariant gather for 'Record': extracts sub-record fields in \(\mathcal{O}(|sub|)\)--- using a reified 'RowMorph'.+-- using a reified 't:RowMorph'. -- -- See Note [Reified Row Morphisms and Gather-Scatter] [ref:note-row-morph-routing] gatherRecord :: RowMorph sub full -> Record full -> Record sub gatherRecord morph (RowRep rep) = RowRep (gatherRep morph rep) -- | Scatter updates for 'Record': overwrites sub-record fields into full record in \(\mathcal{O}(|full|)\)--- using a reified 'RowMorph'.+-- using a reified 't:RowMorph'. -- -- See Note [Reified Row Morphisms and Gather-Scatter] [ref:note-row-morph-routing] scatterRecord :: RowMorph sub full -> Record sub -> Record full -> Record full scatterRecord morph (RowRep sub) (RowRep full) = RowRep (scatterRep morph sub full) --- | High-level record runner for 'FramePlan': merges the previous frame @frameIn@+-- | High-level record runner for 't:FramePlan': merges the previous frame @frameIn@ -- and the operation output @opOut@ into the next frame @frameOut@ in two tight loops. -- -- See Note [Frame-Rule Automatic Wire Synthesis] [ref:note-frame-rule-wiring]@@ -987,11 +1012,11 @@ -- | Map a class-constrained function over all fields of a record. -- -- Algorithmic Mechanics:--- 1. Fetches pre-resolved dictionary vector @fieldDicts@ (a contiguous 'SmallArray'--- of type-erased 'DictAny' entries).--- 2. Clones the underlying payload array into a mutable 'SmallMutableArray' in ST.+-- 1. Fetches pre-resolved dictionary vector @fieldDicts@ (a contiguous 'Data.Primitive.SmallArray.SmallArray'+-- of type-erased 't:DictAny' entries).+-- 2. Clones the underlying payload array into a mutable 'Data.Primitive.SmallArray.SmallMutableArray' in ST. -- 3. In a tight unrolled loop from 0 to N-1:--- - Fetches the dictionary at slot @i@ and unpacks 'DictAny', bringing @c Any@ into scope.+-- - Fetches the dictionary at slot @i@ and unpacks 't:DictAny', bringing @c Any@ into scope. -- - Fetches the payload at slot @i@, coerces to @Any@, and invokes @f@. -- - Writes the coerced result back into slot @i@ in-place. -- 4. Freezes the mutable array into an immutable 'Record'.@@ -1025,7 +1050,7 @@ -- -- Algorithmic Mechanics: -- Recursively traverses the dictionary vector and payload array from index 0 to N-1.--- For each slot, unpacks 'DictAny', maps the value using @f@ to a monoidal value @m@,+-- For each slot, unpacks 't:DictAny', maps the value using @f@ to a monoidal value @m@, -- and combines the results using '<>'. -- -- Complexity: Zero heap array allocations.@@ -1125,5 +1150,25 @@ let val = f (noInlineUnsafeCo vi :: Any) in val <> loop (i + 1) in loop 0++{-------------------------------------------------------------------------------+ §1.8 SOP Record & Variant Coercions+-------------------------------------------------------------------------------}++-- | Coerce a 'RowRep' at 'Identity' to a 'Record' in \(\mathcal{O}(1)\) time.+htoRecord :: RowRep Identity ProductRowT row a -> Record row+htoRecord = unsafeCoerce++-- | Coerce a 'Record' to a 'RowRep' in \(\mathcal{O}(1)\) time.+hfromRecord :: Record row -> RowRep Identity ProductRowT row a+hfromRecord = unsafeCoerce++-- | Coerce a 'RowRep' at 'Identity' to a 'Variant' in \(\mathcal{O}(1)\) time.+htoVariant :: RowRep Identity SumRowT row a -> Variant row+htoVariant = unsafeCoerce++-- | Coerce a 'Variant' to a 'RowRep' in \(\mathcal{O}(1)\) time.+hfromVariant :: Variant row -> RowRep Identity SumRowT row a+hfromVariant = unsafeCoerce
src/Polytropos/Core.hs view
@@ -133,6 +133,7 @@ , AllFields(..) , DictAllFields , SubRow(..)+ , type (:-) , SubSum(..) , KnownHash(..) , labelHash@@ -359,10 +360,10 @@ -- Can be constructed ergonomically via @OverloadedLabels@ (e.g. @#foo@). -- -- Algorithmic Mechanics:--- 'Field' has no runtime fields and is represented by GHC as a zero-cost singleton.+-- t'Field' has no runtime fields and is represented by GHC as a zero-cost singleton. -- When the user writes @#foo@, GHC desugars this to @fromLabel @"foo"@. The -- 'IsLabel' instance below matches when the label string @l@ unifies with the--- expected field symbol @l'@, constructing 'Field' at compile time with zero+-- expected field symbol @l'@, constructing t'Field' at compile time with zero -- runtime allocation. data Field (n :: Symbol) = Field @@ -566,7 +567,7 @@ -- Zero-Cost Newtype Erasure: -- GHC's Core compiler completely unwraps @RowRep@ at compile time. At runtime, -- all operations on @RowRep@ compile down to direct primitive instructions on--- the underlying 'Rep'. The type arguments @r@ and @row@ act as purely type-level+-- the underlying t'Rep'. The type arguments @r@ and @row@ act as purely type-level -- evidence tags, allowing typeclasses like 'RowEq', 'RowShow', and 'AllFields' -- to be invoked directly on records without requiring explicit runtime proxies. data RowRep (f :: Type -> Type) (r :: RowType) (row :: k) a = RowRep (Rep f a)@@ -635,7 +636,7 @@ -- -- [ref:note-transient-cow] -- Allows O(1) in-place slot modification during multi-field updates, bulk parsing,--- or database row decoding without allocating intermediate immutable 'SmallArray'+-- or database row decoding without allocating intermediate immutable 't:SmallArray' -- wrappers. data MRep s (f :: Type -> Type) a = MRep {-# UNPACK #-} !Word@@ -651,7 +652,7 @@ -- | Safely thaw an immutable t'Rep' into a mutable builder. ----- Performs a single heap allocation of a 'SmallMutableArray' and copies the N+-- Performs a single heap allocation of a 't:SmallMutableArray' and copies the N -- pointers from the source array. thawRep :: Rep f a -> ST s (MRep s f a) thawRep (Rep t v) = do@@ -667,7 +668,7 @@ -- | Safely freeze an ephemeral builder into an immutable t'Rep'. -- -- Uses 'unsafeFreezeSmallArray', which is an O(1) zero-copy operation that reuses--- the mutable buffer directly as an immutable 'SmallArray'. Safe because caller+-- the mutable buffer directly as an immutable 't:SmallArray'. Safe because caller -- relinquishes all mutable references in the enclosing 'ST' action. freezeRep :: MRep s f a -> ST s (Rep f a) freezeRep (MRep t m) = do@@ -697,8 +698,8 @@ -- | Scoped pure modification wrapper. ----- Safely thaws an immutable 'Rep', runs an ST-scoped mutation callback, and freezes--- the result back into an immutable 'Rep' without exposing mutable state.+-- Safely thaws an immutable t'Rep', runs an ST-scoped mutation callback, and freezes+-- the result back into an immutable t'Rep' without exposing mutable state. modifyRep :: Rep f a -> (forall s. MRep s f a -> ST s ()) -> Rep f a modifyRep (Rep t v) act = Rep t $ runSmallArray $ do m <- thawSmallArray v 0 (sizeofSmallArray v)@@ -713,7 +714,7 @@ -- -- [ref:note-rep-memory-physics] -- The tag is @0@: a product is the one-constructor sum. The payload values--- are placed directly into a contiguous 'SmallArray'.+-- are placed directly into a contiguous 't:SmallArray'. productRep :: [f Any] -> Rep f a productRep xs = Rep 0 (smallArrayFromList xs) @@ -845,7 +846,7 @@ matchRep :: (Word -> [f Any] -> a) -> Rep f a -> a matchRep k r = k (repTag r) (toListSlots (repVals r)) --- | Eliminate a sum passing the payload as a flat 'SmallArray' without list allocation.+-- | Eliminate a sum passing the payload as a flat 't:SmallArray' without list allocation. matchRepArr :: (Word -> SmallArray (f Any) -> a) -> Rep f a -> a matchRepArr k r = k (repTag r) (repVals r) @@ -908,9 +909,9 @@ -- | Field-wise @Show@ for a product row. See 'RowEq' for the design. -- -- [ref:note-literal-evidence]--- The plugin synthesizes an unrolled sequence of per-field `showsPrec` calls,+-- The plugin synthesizes an unrolled sequence of per-field @showsPrec@ calls, -- formatting each field label as a literal string @"fieldname = "@ followed by--- the field value's `showsPrec`, joined by comma separators.+-- the field value's @showsPrec@, joined by comma separators. class RowFlavour r => RowShow (r :: RowType) (row :: k) where repShowsPrec :: Int -> RowRep f r row a -> ShowS repShowsPrec _ _ = undefined@@ -923,10 +924,10 @@ -- -- [ref:note-literal-evidence] -- Algorithmic Mechanics:--- Two variant values `v1` and `v2` are equal iff:--- 1. Their runtime tags match: `repTag v1 == repTag v2`+-- Two variant values @v1@ and @v2@ are equal iff:+-- 1. Their runtime tags match: @repTag v1 == repTag v2@ -- 2. Their payload fields for that specific active constructor match.--- The plugin emits a Core `case` expression on the tag, branching into per-constructor+-- The plugin emits a Core @case@ expression on the tag, branching into per-constructor -- literal slot equality comparisons. class RowFlavour r => RowEqSum (r :: RowType) (row :: k) where repEqSum :: RowRep f r row a -> RowRep f r row a -> Bool@@ -935,7 +936,7 @@ -- | Field-wise @Show@ for a sum row. -- -- [ref:note-literal-evidence]--- The plugin generates a jump table on `repTag`, emitting the constructor name+-- The plugin generates a jump table on @repTag@, emitting the constructor name -- as a string literal followed by its payload record's field representations. class RowFlavour r => RowShowSum (r :: RowType) (row :: k) where repShowsPrecSum :: Int -> RowRep f r row a -> ShowS@@ -949,9 +950,9 @@ -- [ref:note-literal-evidence] -- [ref:note-poly-kinded-indexing] -- Algorithmic Mechanics:--- When GHC encounters a wanted constraint `FieldIndex "foo" r a`, the plugin--- scans the type-level list `r` for the entry `"foo" ':= a`. It returns the--- 0-based integer offset directly as a Core literal `Lit (MachInt i)`.+-- When GHC encounters a wanted constraint @FieldIndex "foo" r a@, the plugin+-- scans the type-level list @r@ for the entry @"foo" ':= a@. It returns the+-- 0-based integer offset directly as a Core literal @Lit (MachInt i)@. type FieldIndex :: forall {kn} k {ka}. kn -> k -> ka -> Constraint class FieldIndex (n :: kn) (row :: k) (a :: ka) where fieldIndex :: Int@@ -965,8 +966,8 @@ -- [ref:note-literal-evidence] -- [ref:note-poly-kinded-indexing] -- Algorithmic Mechanics:--- For wanted `ConstructorIndex "Bar" s`, the plugin locates `"Bar"` in the sum--- row `s` and produces an unboxed integer literal `Lit (MachWord t)`.+-- For wanted @ConstructorIndex "Bar" s@, the plugin locates @"Bar"@ in the sum+-- row @s@ and produces an unboxed integer literal @Lit (MachWord t)@. type ConstructorIndex :: forall {kn} k. kn -> k -> Constraint class ConstructorIndex (n :: kn) (row :: k) where constructorIndex :: Word@@ -987,9 +988,9 @@ -- Algorithmic Mechanics: -- Under the hood, GHC typeclass dictionaries are ordinary record values containing -- function pointers (vtable). Because all boxed heap objects have identical runtime--- representation (a pointer), a dictionary for `c a` can be coerced to `c Any` via--- 'noInlineUnsafeCo'. At point of consumption, passing an `Any` value cast from `a`--- to a method in `c Any` is completely type-safe because the vtable functions match+-- representation (a pointer), a dictionary for @c a@ can be coerced to @c Any@ via+-- 'noInlineUnsafeCo'. At point of consumption, passing an @Any@ value cast from @a@+-- to a method in @c Any@ is completely type-safe because the vtable functions match -- the actual runtime type of the value. data DictAny (c :: Type -> Constraint) where DictAny :: c Any => DictAny c@@ -1004,7 +1005,7 @@ -- | Construct evidence for the 'AllFields' class. -- -- Takes a list of type-erased dictionaries and places them into a contiguous--- 'SmallArray' for O(1) indexed lookup during generic loops.+-- 't:SmallArray' for O(1) indexed lookup during generic loops. {-# NOINLINE evidenceAllFields #-} evidenceAllFields :: forall c. [DictAny c] -> DictAllFields c evidenceAllFields = smallArrayFromList@@ -1064,8 +1065,8 @@ -- -- Algorithmic Mechanics: -- Walks the field dictionary array and the two value arrays in lockstep from--- index 0 to N-1. For each slot, unpacks `DictAny`, casts both values to `Any`,--- and calls `compare`. If `EQ`, advances to the next slot; otherwise immediately+-- index 0 to N-1. For each slot, unpacks @DictAny@, casts both values to @Any@,+-- and calls @compare@. If @EQ@, advances to the next slot; otherwise immediately -- terminates with the comparison result. instance (RowEq ProductRowT row, AllFields ProductRowT row Ord) => Ord (RowRep f ProductRowT row a) where compare (RowRep r1) (RowRep r2) =@@ -1144,9 +1145,9 @@ -- as evidence. -- -- Algorithmic Mechanics:--- For sub-record projection `projectRecord @sub superRec`, the runtime must extract+-- For sub-record projection @projectRecord \@sub superRec@, the runtime must extract -- the subset of fields in @sub@ from @super@. The @subRowIndices@ method returns a--- precomputed permutation vector `[Int]` containing the exact slot indices in @super@.+-- precomputed permutation vector @[Int]@ containing the exact slot indices in @super@. -- This allows projection to execute in a single O(|sub|) pass with zero type search. type SubRow :: forall {k1} {k2}. k1 -> k2 -> Constraint class SubRow (sub :: k1) (super :: k2) where@@ -1154,6 +1155,10 @@ subRowIndices :: [Int] subRowIndices = undefined +-- | Infix constraint alias for 'SubRow': @sub :- super@ witnesses that @sub@ is a sub-row of @super@.+type (:-) = SubRow+infix 4 :-+ -- | Sub-sum relationship between two sum rows (variant widening & narrowing). -- -- [ref:note-subrow-subsum] [ref:note-subrow-subsum-mechanics]@@ -1162,13 +1167,13 @@ -- (for widening) and narrowing tag indices (for projection) as evidence. -- -- Algorithmic Mechanics:--- 1. Widening (`widenVariant`):+-- 1. Widening (@widenVariant@): -- Total and O(1). Every constructor in @sub@ is present in @super@. The runtime tag--- `t` in @sub@ is mapped to `subSumInjectIndices !! fromIntegral t`, which is+-- @t@ in @sub@ is mapped to @subSumInjectIndices !! fromIntegral t@, which is -- precomputed by the plugin.--- 2. Narrowing (`narrowVariant`):--- Partial and O(1). Inspects `subSumNarrowIndices !! fromIntegral t`. If the constructor--- is present in @sub@, returns `Just subTag`; otherwise `Nothing`.+-- 2. Narrowing (@narrowVariant@):+-- Partial and O(1). Inspects @subSumNarrowIndices !! fromIntegral t@. If the constructor+-- is present in @sub@, returns @Just subTag@; otherwise 'Nothing'. type SubSum :: forall {k1} {k2}. k1 -> k2 -> Constraint class SubSum (sub :: k1) (super :: k2) where -- | For each constructor in @sub@, its tag in @super@ (widening).@@ -1202,9 +1207,12 @@ -- -- Algorithmic Mechanics: -- The FNV-1a 64-bit algorithm evaluates over the UTF-8 bytes of the label string:+--+-- @ -- hash = 14695981039346656037 (offset basis) -- for each byte c: -- hash = (hash `xor` c) * 1099511628211 (prime)+-- @ type KnownHash :: Symbol -> Constraint class KnownHash (s :: Symbol) where -- | Literal compile-time hash for label @s@.
+ src/Polytropos/Core/SOP.hs view
@@ -0,0 +1,1027 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE ExplicitNamespaces #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE QuantifiedConstraints #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneKindSignatures #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -Wno-redundant-constraints #-}++{-|+Module : Polytropos.Core.SOP+Description : SOP (Sums-of-Products) combinators over flat generic representations+Copyright : (c) 2026 The Polytropos Authors+License : EUPL-1.2 OR Apache-2.0+Maintainer : nadia.yvette.chambers@ik.me+Stability : experimental+Portability : non-portable (GHC extensions)++High-performance Sums-of-Products (SOP) combinators over the uniform 'Polytropos.Core.Rep'+and 'Polytropos.Core.RowRep' substrates of Polytropos.++= Architectural Overview & Heritage++In traditional SOP libraries such as @generics-sop@ and @sop-core@:+* Products (@NP f xs@) and sums (@NS f xs@) are inductive GADTs.+* Combinators such as @hpure@, @hliftA2@, and @hcollapse@ operate via structural+ recursion over an inductive singleton spine (@SListI xs@) or unary Peano tag+ trees (@Z@, @S@), paying \(\mathcal{O}(N)\) spine allocations and recursion depth.++In @polytropos@, both products ('ProductRowT') and sums ('SumRowT') share a single,+flat, type-erased runtime representation:++@+data Rep (f :: Type -> Type) a = Rep {-# UNPACK #-} !Word !(SmallArray (f Any))+newtype RowRep (f :: Type -> Type) (r :: RowType) (row :: k) a = RowRep (Rep f a)+@++Because 'Polytropos.Core.RowRep' already parameterizes every payload slot by a functor+@f :: Type -> Type@, we obtain:+1. __Zero-Spine Execution:__ 'hcollapse', 'hliftA2', and 'hsequence' operate directly+ over contiguous 'Data.Primitive.SmallArray.SmallArray' slices in \(\mathcal{O}(1)\)+ allocation without intermediate list or GADT node allocations.+2. __Zero-Constraint Primitives:__ Unconstrained combinators like 'hliftA2', 'hsequence',+ and 'hcollapse' require no typeclass evidence (@AllFields@ or @SListI@) because+ the arity and constructor tag are stored directly in the runtime representation.+3. __\(\mathcal{O}(1)\) Sum Operations:__ Sum branch indexing ('hindex'), application ('hapSum'),+ and elimination ('helim') execute in instantaneous \(\mathcal{O}(1)\) time by indexing+ directly via the unboxed runtime 'Polytropos.Core.repTag'.+4. __Zero-Copy Coercions:__ Because all slots have erased runtime layout @f Any@,+ functor changes under 'Data.Coerce.Coercible' ('hcoerce', 'htoI', 'hfromI') are pure \(\mathcal{O}(1)\)+ no-ops that preserve the identical heap array pointer.+-}+module Polytropos.Core.SOP+ ( -- * Functor Types & Aliases+ I(..)+ , type K+ , unK+ , type (:.:)+ , unComp+ , comp+ , type (-.->)(..)+ -- * Universal Constraints & Reflection+ , Top+ , ReifyFieldNames(..)+ -- * Population+ , hpure+ , hpureFromNames+ , hpureArity+ , hcpure+ , hcpure_+ -- * Mapping & Zipping+ , hmap+ , hliftA+ , hcmapProduct+ , hcmapSum+ , HCMap(..)+ , hcmap+ , hcmap_+ , hcliftA+ , hcliftA_+ , hliftA2+ , hzipWith+ , hliftA2Sum+ , hcliftA2+ , hczipWith+ , hcliftA2_+ , hcliftA2Sum+ , hliftA3+ , hzipWith3+ , hcliftA3+ , hczipWith3+ , hcliftA3_+ , hproduct+ , hunzip+ -- * Application & Elimination+ , hapProduct+ , hap+ , hapSum+ , helim+ -- * Folding & Collapsing+ , hcollapse+ , hcollapseFold+ , hfoldMap+ , hcfoldMap+ , hcfoldMap_+ , hcfoldMapSum+ -- * Traversing & Sequencing+ , hsequence'+ , hsequence+ , htraverse+ , hctraverse+ , hctraverse_+ -- * Sum Operations+ , hindex+ , hexpandArity+ , hexpand+ , injectionsArity+ , injections+ , apInjs+ , hhead+ -- * Zero-Copy Coercions & Metadata+ , hcoerce+ , htoI+ , hfromI+ , hunit+ , hdeunit+ , hfieldNames+ ) where++import Control.Monad.ST (runST)+import Data.Coerce (Coercible, coerce)+import Data.Foldable (toList)+import Data.Functor.Compose (Compose(..))+import Data.Functor.Const (Const(..))+import Data.Functor.Identity (Identity(..))+import qualified Data.Functor.Product as FP+import Data.Kind (Constraint)+import Data.Primitive.SmallArray+ ( indexSmallArray+ , newSmallArray+ , runSmallArray+ , sizeofSmallArray+ , smallArrayFromListN+ , unsafeFreezeSmallArray+ , writeSmallArray+ )+import Data.Proxy (Proxy(..))+import GHC.Exts (Any)+import GHC.TypeLits (KnownSymbol, symbolVal)+import Unsafe.Coerce (unsafeCoerce)++import Polytropos.Core+ ( AllFields(..)+ , DictAny(..)+ , Pair(..)+ , Rep(..)+ , RowFlavour+ , RowRep(..)+ , RowType(ProductRowT, SumRowT)+ , fieldAt+ , productRep+ )++{-------------------------------------------------------------------------------+ §1 Functor Types & Aliases+-------------------------------------------------------------------------------}++-- | Identity functor matching @generics-sop@ / @sop-core@ and @Polytropos.Generics@.+newtype I a = I { unI :: a }+ deriving (Eq, Ord, Show, Read)++-- | Constant functor alias matching @generics-sop@ / @sop-core@.+type K = Const++-- | Extract the value from a 'K' ('Const') wrapper.+unK :: K a b -> a+unK (Const x) = x++-- | Functor composition operator matching @generics-sop@ / @sop-core@.+type (:.:) = Compose+infixr 8 :.:++-- | Unpack a composed functor wrapper.+unComp :: (f :.: g) a -> f (g a)+unComp (Compose x) = x++-- | Pack a nested functor value into a composed functor wrapper.+comp :: f (g a) -> (f :.: g) a+comp = Compose++-- | Lifted natural transformation / function arrow between functors.+--+-- Mirrors @generics-sop@'s @(-.->)@.+newtype (-.->) f g a = Fn { apFn :: f a -> g a }+infixr 1 -.->++{-------------------------------------------------------------------------------+ §2 Universal Constraints & Reflection+-------------------------------------------------------------------------------}++-- | Universal constraint that holds trivially for every type and kind.+--+-- Used to instantiate constrained combinators ('hcpure', 'hcmap', etc.)+-- without restricting field types.+class Top (a :: k)+instance Top (a :: k)++-- | Reify field or constructor names from a type-level row into runtime 'String' values.+type ReifyFieldNames :: forall {k}. k -> Constraint+class ReifyFieldNames (r :: k) where+ reifyFieldNames :: [String]++instance ReifyFieldNames '[] where+ reifyFieldNames = []++instance (KnownSymbol n, ReifyFieldNames rest) => ReifyFieldNames ((n ':= a) ': rest) where+ reifyFieldNames = symbolVal (Proxy @n) : reifyFieldNames @rest++instance {-# OVERLAPPABLE #-} (KnownSymbol n, ReifyFieldNames rest) => ReifyFieldNames (n ': rest) where+ reifyFieldNames = symbolVal (Proxy @n) : reifyFieldNames @rest++{-------------------------------------------------------------------------------+ §3 Population+-------------------------------------------------------------------------------}++-- | Populate a product 'RowRep' using an unconstrained rank-2 value generator.+--+-- Requires 'AllFields' 'ProductRowT' @row@ 'Top' to determine the row arity+-- at compile time.+hpure+ :: forall row f a.+ AllFields ProductRowT row Top+ => (forall x. f x)+ -> RowRep f ProductRowT row a+hpure fn =+ let dicts = fieldDicts @ProductRowT @row @Top+ n = sizeofSmallArray dicts+ arr = runSmallArray $ do+ dst <- newSmallArray n (error "hpure: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ writeSmallArray dst i (fn @Any)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arr)++-- | Populate a product 'RowRep' using row field names to determine arity.+--+-- Useful in contexts where 'ReifyFieldNames' is available instead of 'AllFields'.+hpureFromNames+ :: forall row f a.+ ReifyFieldNames row+ => (forall x. f x)+ -> RowRep f ProductRowT row a+hpureFromNames fn = hpureArity (length (reifyFieldNames @row)) fn++-- | Populate a product 'RowRep' of a given explicit integer arity.+hpureArity+ :: Int+ -> (forall x. f x)+ -> RowRep f ProductRowT row a+hpureArity n fn =+ let arr = runSmallArray $ do+ dst <- newSmallArray n (error "hpureArity: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ writeSmallArray dst i (fn @Any)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arr)++-- | Populate a product 'RowRep' using a class-constrained rank-2 builder.+--+-- Uses the dictionary vector emitted by @polytropos-plugin@ to supply+-- the class constraint @c x@ for each slot.+hcpure+ :: forall c row f a.+ AllFields ProductRowT row c+ => (forall x. c x => f x)+ -> RowRep f ProductRowT row a+hcpure fn =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ arr = runSmallArray $ do+ dst <- newSmallArray n (error "hcpure: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise =+ case indexSmallArray dicts i of+ DictAny -> do+ writeSmallArray dst i (fn @Any)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arr)++-- | Proxy-passing variant of 'hcpure' for @generics-sop@ API compatibility.+hcpure_+ :: forall c row f a proxy.+ AllFields ProductRowT row c+ => proxy c+ -> (forall x. c x => f x)+ -> RowRep f ProductRowT row a+hcpure_ _ fn = hcpure @c @row fn++{-------------------------------------------------------------------------------+ §4 Mapping & Zipping+-------------------------------------------------------------------------------}++-- | Map a natural transformation over all payload slots of a 'RowRep'.+--+-- Requires zero typeclass constraints. Works uniformly over 'ProductRowT'+-- (records) and 'SumRowT' (variants), preserving the constructor tag.+hmap+ :: (forall x. f x -> g x)+ -> RowRep f r row a+ -> RowRep g r row a+hmap fn (RowRep (Rep tag vals)) =+ let n = sizeofSmallArray vals+ vals' = runSmallArray $ do+ dst <- newSmallArray n (error "hmap: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !v = indexSmallArray vals i+ writeSmallArray dst i (fn v)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep tag vals')++-- | Alias for 'hmap' matching the @generics-sop@ naming convention.+hliftA+ :: (forall x. f x -> g x)+ -> RowRep f r row a+ -> RowRep g r row a+hliftA = hmap++-- | Map a class-constrained function over a product 'RowRep'.+hcmapProduct+ :: forall c row f g a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+hcmapProduct fn (RowRep (Rep tag vals)) =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ vals' = runSmallArray $ do+ dst <- newSmallArray n (error "hcmapProduct: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise =+ case indexSmallArray dicts i of+ DictAny -> do+ let !v = indexSmallArray vals i+ writeSmallArray dst i (fn @Any v)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep tag vals')++-- | Map a class-constrained function over a sum 'RowRep' in \(\mathcal{O}(1)\) time.+--+-- Indexes the dictionary vector directly using the variant's active constructor tag.+hcmapSum+ :: forall c row f g a.+ AllFields SumRowT row c+ => (forall x. c x => f x -> g x)+ -> RowRep f SumRowT row a+ -> RowRep g SumRowT row a+hcmapSum fn (RowRep (Rep tag vals)) =+ let dicts = fieldDicts @SumRowT @row @c+ !d = indexSmallArray dicts (fromIntegral tag)+ n = sizeofSmallArray vals+ vals' = case d of+ DictAny -> runSmallArray $ do+ dst <- newSmallArray n (error "hcmapSum: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !v = indexSmallArray vals i+ writeSmallArray dst i (fn @Any v)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep tag vals')++-- | Unified class for constrained mapping over either products or sums.+class RowFlavour r => HCMap (r :: RowType) where+ -- | Internal implementation method for constrained mapping.+ hcmapImpl+ :: forall c row f g a.+ AllFields r row c+ => (forall x. c x => f x -> g x)+ -> RowRep f r row a+ -> RowRep g r row a++instance HCMap ProductRowT where+ hcmapImpl = hcmapProduct++instance HCMap SumRowT where+ hcmapImpl = hcmapSum++-- | Unified constrained map over either a product or sum 'RowRep'.+--+-- The constraint @c@ is passed first via TypeApplications (e.g. @hcmap @Show fn rep@),+-- while the row flavour @r@ and row structure are inferred directly from the argument.+hcmap+ :: forall c r row f g a.+ (HCMap r, AllFields r row c)+ => (forall x. c x => f x -> g x)+ -> RowRep f r row a+ -> RowRep g r row a+hcmap = hcmapImpl @r @c++-- | Proxy-passing variant of 'hcmap' for @generics-sop@ API compatibility.+hcmap_+ :: forall c r row f g a proxy.+ (HCMap r, AllFields r row c)+ => proxy c+ -> (forall x. c x => f x -> g x)+ -> RowRep f r row a+ -> RowRep g r row a+hcmap_ _ = hcmap @c++-- | Alias for 'hcmapProduct' matching @generics-sop@ conventions.+hcliftA+ :: forall c row f g a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+hcliftA = hcmapProduct++-- | Proxy-passing variant of 'hcliftA' for @generics-sop@ API compatibility.+hcliftA_+ :: forall c row f g a proxy.+ AllFields ProductRowT row c+ => proxy c+ -> (forall x. c x => f x -> g x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+hcliftA_ _ = hcmapProduct @c++-- | Unconstrained pointwise zip of two product 'RowRep' values.+--+-- Requires zero typeclass constraints.+hliftA2+ :: (forall x. f x -> g x -> h x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+hliftA2 fn (RowRep (Rep _ arrF)) (RowRep (Rep _ arrG)) =+ let n = sizeofSmallArray arrF+ arrH = runSmallArray $ do+ dst <- newSmallArray n (error "hliftA2: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !fx = indexSmallArray arrF i+ !gx = indexSmallArray arrG i+ writeSmallArray dst i (fn fx gx)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arrH)++-- | Alias for 'hliftA2'.+hzipWith+ :: (forall x. f x -> g x -> h x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+hzipWith = hliftA2++-- | Pointwise zip of two sum 'RowRep' values.+--+-- Succeeds with 'Just' iff both variants share the same active constructor tag.+hliftA2Sum+ :: (forall x. f x -> g x -> h x)+ -> RowRep f SumRowT row a+ -> RowRep g SumRowT row a+ -> Maybe (RowRep h SumRowT row a)+hliftA2Sum fn (RowRep (Rep tagF arrF)) (RowRep (Rep tagG arrG))+ | tagF == tagG =+ let n = sizeofSmallArray arrF+ arrH = runSmallArray $ do+ dst <- newSmallArray n (error "hliftA2Sum: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !fx = indexSmallArray arrF i+ !gx = indexSmallArray arrG i+ writeSmallArray dst i (fn fx gx)+ go (i + 1)+ go 0+ pure dst+ in Just (RowRep (Rep tagF arrH))+ | otherwise = Nothing++-- | Constrained pointwise zip of two product 'RowRep' values.+hcliftA2+ :: forall c row f g h a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x -> h x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+hcliftA2 fn (RowRep (Rep _ arrF)) (RowRep (Rep _ arrG)) =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ arrH = runSmallArray $ do+ dst <- newSmallArray n (error "hcliftA2: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise =+ case indexSmallArray dicts i of+ DictAny -> do+ let !fx = indexSmallArray arrF i+ !gx = indexSmallArray arrG i+ writeSmallArray dst i (fn @Any fx gx)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arrH)++-- | Alias for 'hcliftA2'.+hczipWith+ :: forall c row f g h a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x -> h x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+hczipWith = hcliftA2++-- | Proxy-passing variant of 'hcliftA2'.+hcliftA2_+ :: forall c row f g h a proxy.+ AllFields ProductRowT row c+ => proxy c+ -> (forall x. c x => f x -> g x -> h x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+hcliftA2_ _ = hcliftA2 @c++-- | Constrained pointwise zip of two sum 'RowRep' values.+--+-- Returns 'Just' iff both variants share the same active constructor tag.+hcliftA2Sum+ :: forall c row f g h a.+ AllFields SumRowT row c+ => (forall x. c x => f x -> g x -> h x)+ -> RowRep f SumRowT row a+ -> RowRep g SumRowT row a+ -> Maybe (RowRep h SumRowT row a)+hcliftA2Sum fn (RowRep (Rep tagF arrF)) (RowRep (Rep tagG arrG))+ | tagF == tagG =+ let dicts = fieldDicts @SumRowT @row @c+ !d = indexSmallArray dicts (fromIntegral tagF)+ n = sizeofSmallArray arrF+ arrH = case d of+ DictAny -> runSmallArray $ do+ dst <- newSmallArray n (error "hcliftA2Sum: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !fx = indexSmallArray arrF i+ !gx = indexSmallArray arrG i+ writeSmallArray dst i (fn @Any fx gx)+ go (i + 1)+ go 0+ pure dst+ in Just (RowRep (Rep tagF arrH))+ | otherwise = Nothing++-- | Unconstrained 3-way zip of product 'RowRep' values.+hliftA3+ :: (forall x. f x -> g x -> h x -> i x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+ -> RowRep i ProductRowT row a+hliftA3 fn (RowRep (Rep _ arrF)) (RowRep (Rep _ arrG)) (RowRep (Rep _ arrH)) =+ let n = sizeofSmallArray arrF+ arrI = runSmallArray $ do+ dst <- newSmallArray n (error "hliftA3: uninitialized slot")+ let go idx+ | idx >= n = pure ()+ | otherwise = do+ let !fx = indexSmallArray arrF idx+ !gx = indexSmallArray arrG idx+ !hx = indexSmallArray arrH idx+ writeSmallArray dst idx (fn fx gx hx)+ go (idx + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arrI)++-- | Alias for 'hliftA3'.+hzipWith3+ :: (forall x. f x -> g x -> h x -> i x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+ -> RowRep i ProductRowT row a+hzipWith3 = hliftA3++-- | Constrained 3-way zip of product 'RowRep' values.+hcliftA3+ :: forall c row f g h i a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x -> h x -> i x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+ -> RowRep i ProductRowT row a+hcliftA3 fn (RowRep (Rep _ arrF)) (RowRep (Rep _ arrG)) (RowRep (Rep _ arrH)) =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ arrI = runSmallArray $ do+ dst <- newSmallArray n (error "hcliftA3: uninitialized slot")+ let go idx+ | idx >= n = pure ()+ | otherwise =+ case indexSmallArray dicts idx of+ DictAny -> do+ let !fx = indexSmallArray arrF idx+ !gx = indexSmallArray arrG idx+ !hx = indexSmallArray arrH idx+ writeSmallArray dst idx (fn @Any fx gx hx)+ go (idx + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arrI)++-- | Alias for 'hcliftA3'.+hczipWith3+ :: forall c row f g h i a.+ AllFields ProductRowT row c+ => (forall x. c x => f x -> g x -> h x -> i x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+ -> RowRep i ProductRowT row a+hczipWith3 = hcliftA3++-- | Proxy-passing variant of 'hcliftA3'.+hcliftA3_+ :: forall c row f g h i a proxy.+ AllFields ProductRowT row c+ => proxy c+ -> (forall x. c x => f x -> g x -> h x -> i x)+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep h ProductRowT row a+ -> RowRep i ProductRowT row a+hcliftA3_ _ = hcliftA3 @c++-- | Combine two product rows pointwise into a single product of pairs.+hproduct+ :: RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+ -> RowRep (FP.Product f g) ProductRowT row a+hproduct = hliftA2 FP.Pair++-- | Split a product row of pairs into two separate product rows in a single pass.+hunzip+ :: RowRep (FP.Product f g) ProductRowT row a+ -> (RowRep f ProductRowT row a, RowRep g ProductRowT row a)+hunzip (RowRep (Rep tag vals)) =+ let n = sizeofSmallArray vals+ (arrF, arrG) = runST $ do+ dstF <- newSmallArray n (error "hunzip: uninitialized slot")+ dstG <- newSmallArray n (error "hunzip: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ case indexSmallArray vals i of+ FP.Pair fx gx -> do+ writeSmallArray dstF i fx+ writeSmallArray dstG i gx+ go (i + 1)+ go 0+ fFrozen <- unsafeFreezeSmallArray dstF+ gFrozen <- unsafeFreezeSmallArray dstG+ pure (fFrozen, gFrozen)+ in (RowRep (Rep tag arrF), RowRep (Rep tag arrG))++{-------------------------------------------------------------------------------+ §5 Application & Elimination+-------------------------------------------------------------------------------}++-- | Pointwise application of a product of functions to a product of arguments.+--+-- Runs in \(\mathcal{O}(N)\) time with zero typeclass constraints.+hapProduct+ :: RowRep (f -.-> g) ProductRowT row a+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+hapProduct = hliftA2 apFn++-- | Alias for 'hapProduct' matching @generics-sop@ convention.+hap+ :: RowRep (f -.-> g) ProductRowT row a+ -> RowRep f ProductRowT row a+ -> RowRep g ProductRowT row a+hap = hapProduct++-- | Apply a product of branch functions to a sum variant in \(\mathcal{O}(1)\) time.+--+-- Direct jump-table dispatch: indexes into the function product using the variant's+-- unboxed runtime tag.+hapSum+ :: RowRep (f -.-> g) ProductRowT row a+ -> RowRep f SumRowT row a+ -> RowRep g SumRowT row a+hapSum (RowRep (Rep _ fnArr)) (RowRep (Rep tag valArr)) =+ let fn = indexSmallArray fnArr (fromIntegral tag)+ n = sizeofSmallArray valArr+ valArr' = runSmallArray $ do+ dst <- newSmallArray n (error "hapSum: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let !v = indexSmallArray valArr i+ writeSmallArray dst i (apFn fn v)+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep tag valArr')++-- | Eliminate a sum variant using a product of handlers in \(\mathcal{O}(1)\) time.+--+-- Fuses 'hapSum' and 'hcollapse' into a single instantaneous array lookup.+helim+ :: RowRep (f -.-> Const b) ProductRowT row a+ -> RowRep f SumRowT row a+ -> b+helim (RowRep (Rep _ fnArr)) (RowRep (Rep tag valArr)) =+ let fn = indexSmallArray fnArr (fromIntegral tag)+ val = indexSmallArray valArr 0+ in getConst (apFn fn val)++{-------------------------------------------------------------------------------+ §6 Folding & Collapsing+-------------------------------------------------------------------------------}++-- | Extract values from a 'RowRep' parameterized by 'Const' into a list.+--+-- Runs in \(\mathcal{O}(N)\) time with zero typeclass constraints and zero+-- 'unsafeCoerce' calls. Works uniformly on both 'ProductRowT' and 'SumRowT'.+hcollapse :: RowRep (Const a) r row x -> [a]+hcollapse (RowRep (Rep _ vals)) =+ let n = sizeofSmallArray vals+ go i+ | i >= n = []+ | otherwise = getConst (indexSmallArray vals i) : go (i + 1)+ in go 0++-- | Foldable-based variant of 'hcollapse'.+hcollapseFold :: RowRep (Const a) r row x -> [a]+hcollapseFold (RowRep (Rep _ vals)) = map getConst (toList vals)++-- | Unconstrained monoidal fold across all payload slots of a 'RowRep'.+--+-- Works on both 'ProductRowT' and 'SumRowT' without allocating an intermediate array.+hfoldMap+ :: Monoid m+ => (forall x. f x -> m)+ -> RowRep f r row a+ -> m+hfoldMap fn (RowRep (Rep _ vals)) =+ let n = sizeofSmallArray vals+ go i+ | i >= n = mempty+ | otherwise = fn (indexSmallArray vals i) <> go (i + 1)+ in go 0++-- | Fused constrained fold over a product 'RowRep'.+--+-- Evaluates directly into a 'Monoid' without allocating an intermediate 'Const' array.+hcfoldMap+ :: forall c row m f a.+ (AllFields ProductRowT row c, Monoid m)+ => (forall x. c x => f x -> m)+ -> RowRep f ProductRowT row a+ -> m+hcfoldMap fn (RowRep (Rep _ vals)) =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ go i+ | i >= n = mempty+ | otherwise =+ case indexSmallArray dicts i of+ DictAny -> fn @Any (indexSmallArray vals i) <> go (i + 1)+ in go 0++-- | Proxy-passing variant of 'hcfoldMap'.+hcfoldMap_+ :: forall c row m f a proxy.+ (AllFields ProductRowT row c, Monoid m)+ => proxy c+ -> (forall x. c x => f x -> m)+ -> RowRep f ProductRowT row a+ -> m+hcfoldMap_ _ = hcfoldMap @c++-- | Fused constrained fold over a sum 'RowRep' in \(\mathcal{O}(1)\) time.+hcfoldMapSum+ :: forall c row m f a.+ (AllFields SumRowT row c, Monoid m)+ => (forall x. c x => f x -> m)+ -> RowRep f SumRowT row a+ -> m+hcfoldMapSum fn (RowRep (Rep tag vals)) =+ let dicts = fieldDicts @SumRowT @row @c+ !d = indexSmallArray dicts (fromIntegral tag)+ n = sizeofSmallArray vals+ go i+ | i >= n = mempty+ | otherwise =+ case d of+ DictAny -> fn @Any (indexSmallArray vals i) <> go (i + 1)+ in go 0++{-------------------------------------------------------------------------------+ §7 Traversing & Sequencing+-------------------------------------------------------------------------------}++-- | Sequence an 'Applicative' effect out of a 'Compose'-wrapped 'RowRep'.+--+-- Works polymorphically on both 'ProductRowT' and 'SumRowT' with zero constraints.+hsequence'+ :: Applicative m+ => RowRep (Compose m f) r row a+ -> m (RowRep f r row a)+hsequence' (RowRep (Rep tag vals)) =+ RowRep . Rep tag <$> traverse getCompose vals++-- | Sequence an 'Applicative' effect directly from 'RowRep' @m@ into 'RowRep' 'Identity'.+hsequence+ :: Applicative m+ => RowRep m r row a+ -> m (RowRep Identity r row a)+hsequence (RowRep (Rep tag vals)) =+ RowRep . Rep tag <$> traverse (fmap Identity) vals++-- | Traverse an 'Applicative' effect over all slots of a 'RowRep'.+--+-- Requires zero typeclass constraints; works on both products and sums.+htraverse+ :: Applicative m+ => (forall x. f x -> m (g x))+ -> RowRep f r row a+ -> m (RowRep g r row a)+htraverse fn (RowRep (Rep tag vals)) =+ RowRep . Rep tag <$> traverse fn vals++-- | Fused constrained traversal over a product 'RowRep'.+--+-- Sequences the 'Applicative' effect without allocating an intermediate 'Compose' array.+hctraverse+ :: forall c row m f g a.+ (AllFields ProductRowT row c, Applicative m)+ => (forall x. c x => f x -> m (g x))+ -> RowRep f ProductRowT row a+ -> m (RowRep g ProductRowT row a)+hctraverse fn (RowRep (Rep tag arrF)) =+ let dicts = fieldDicts @ProductRowT @row @c+ n = sizeofSmallArray dicts+ go :: Int -> m [g Any]+ go i+ | i >= n = pure []+ | otherwise =+ case indexSmallArray dicts i of+ DictAny -> (:) <$> fn @Any (indexSmallArray arrF i) <*> go (i + 1)+ in RowRep . Rep tag . smallArrayFromListN n <$> go 0++-- | Proxy-passing variant of 'hctraverse'.+hctraverse_+ :: forall c row m f g a proxy.+ (AllFields ProductRowT row c, Applicative m)+ => proxy c+ -> (forall x. c x => f x -> m (g x))+ -> RowRep f ProductRowT row a+ -> m (RowRep g ProductRowT row a)+hctraverse_ _ = hctraverse @c++{-------------------------------------------------------------------------------+ §8 Sum Operations (O(1))+-------------------------------------------------------------------------------}++-- | Active constructor index of a sum 'RowRep' in \(\mathcal{O}(1)\) time.+hindex :: RowRep f SumRowT row a -> Int+hindex (RowRep (Rep tag _)) = fromIntegral tag++-- | Expand a sum 'RowRep' into a product 'RowRep' with 'Just' at the active tag+-- and 'Nothing' elsewhere, using explicit arity.+hexpandArity+ :: Int+ -> RowRep f SumRowT row a+ -> RowRep (Compose Maybe f) ProductRowT row a+hexpandArity n (RowRep (Rep tag valArr)) =+ let val = indexSmallArray valArr 0+ arr = runSmallArray $ do+ dst <- newSmallArray n (Compose Nothing)+ writeSmallArray dst (fromIntegral tag) (Compose (Just val))+ pure dst+ in RowRep (Rep 0 arr)++-- | Expand a sum 'RowRep' into a product 'RowRep' with 'Just' at the active tag+-- and 'Nothing' elsewhere.+hexpand+ :: forall row f a.+ ReifyFieldNames row+ => RowRep f SumRowT row a+ -> RowRep (Compose Maybe f) ProductRowT row a+hexpand = hexpandArity (length (reifyFieldNames @row))++-- | Produce a product of constructor injection functions for a given arity.+injectionsArity+ :: forall row f a.+ Int+ -> RowRep (f -.-> Const (RowRep f SumRowT row a)) ProductRowT row a+injectionsArity n =+ let arr = runSmallArray $ do+ dst <- newSmallArray n (error "injectionsArity: uninitialized slot")+ let go i+ | i >= n = pure ()+ | otherwise = do+ let inj = Fn (\val -> Const (RowRep (Rep (fromIntegral i) (smallArrayFromListN 1 [val]))))+ writeSmallArray dst i inj+ go (i + 1)+ go 0+ pure dst+ in RowRep (Rep 0 arr)++-- | Produce a product of constructor injection functions.+injections+ :: forall row f a.+ ReifyFieldNames row+ => RowRep (f -.-> Const (RowRep f SumRowT row a)) ProductRowT row a+injections = injectionsArity (length (reifyFieldNames @row))++-- | Convert each slot of a product 'RowRep' into its corresponding sum variant.+apInjs :: RowRep f ProductRowT row a -> [RowRep f SumRowT row a]+apInjs (RowRep (Rep _ arr)) =+ let n = sizeofSmallArray arr+ go i+ | i >= n = []+ | otherwise =+ let v = indexSmallArray arr i+ in RowRep (Rep (fromIntegral i) (smallArrayFromListN 1 [v])) : go (i + 1)+ in go 0++-- | Extract the first slot of a product row.+hhead :: RowRep f ProductRowT row a -> f Any+hhead (RowRep rep) = fieldAt 0 rep++{-------------------------------------------------------------------------------+ §9 Zero-Copy Coercions & Metadata+-------------------------------------------------------------------------------}++-- | \(\mathcal{O}(1)\) zero-copy coercion between representationally identical slot functors+-- (e.g. 'Identity' and 'I', 'Const' and 'K', or newtype wrappers).+--+-- Reuses the identical 'Data.Primitive.SmallArray.SmallArray' pointer without copying+-- or allocating.+hcoerce+ :: forall f g r row a.+ (forall x. Coercible (f x) (g x))+ => RowRep f r row a+ -> RowRep g r row a+hcoerce rep =+ let !_ = coerce (id :: f () -> f ()) :: g () -> g ()+ in unsafeCoerce rep++-- | Coerce a functorial 'RowRep' to an 'Identity'-wrapped 'RowRep' in \(\mathcal{O}(1)\) time.+htoI+ :: forall f r row a.+ (forall x. Coercible (f x) (Identity x))+ => RowRep f r row a+ -> RowRep Identity r row a+htoI = unsafeCoerce++-- | Coerce an 'Identity'-wrapped 'RowRep' to another representationally identical functor in \(\mathcal{O}(1)\) time.+hfromI+ :: forall f r row a.+ (forall x. Coercible (Identity x) (f x))+ => RowRep Identity r row a+ -> RowRep f r row a+hfromI = unsafeCoerce++-- | Coerce a 'RowRep' with arbitrary result type @a@ to @()@.+hunit :: RowRep f r row a -> RowRep f r row ()+hunit = unsafeCoerce++-- | Coerce a 'RowRep' with result type @()@ to arbitrary @a@.+hdeunit :: RowRep f r row () -> RowRep f r row a+hdeunit = unsafeCoerce++-- | Reify row field or constructor labels as a 'Const' 'String'-wrapped product 'RowRep',+-- ready to be zipped with values via 'hliftA2' or 'hcliftA2'.+hfieldNames+ :: forall row a.+ ReifyFieldNames row+ => RowRep (Const String) ProductRowT row a+hfieldNames =+ let names = map Const (reifyFieldNames @row)+ in RowRep (productRep names)
+ src/Polytropos/MergeMorph.hs view
@@ -0,0 +1,148 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UnboxedTuples #-}++-- |+-- Module : Polytropos.MergeMorph+-- Description : Skew Boolean Intersection Algebra and O(|rOut|) two-source gather morphs.+--+-- Implements the Skew Boolean Intersection Algebra (Leech 1990; Cockett & Lack 2002)+-- over flat 'Polytropos.Record' arrays using a single unboxed 'PrimArray' gather plan.+module Polytropos.MergeMorph+ ( MergeOp(..)+ , MergeMorph(..)+ , KnownMergeMorph(..)+ , executeMergeMorph+ , unsafeMkMergeMorph+ , unsafeMkMergeMorph#+ , (//>)+ , (<//)+ , (<+>)+ , (//~)+ , (|<)+ , (/-/)+ , (\^/)+ ) where++import Control.Monad.ST (runST)+import Data.Bits (complement)+import Data.Primitive.PrimArray (PrimArray(..), indexPrimArray, primArrayFromList, sizeofPrimArray)+import Data.Primitive.SmallArray (indexSmallArray, newSmallArray, runSmallArray, writeSmallArray)+import GHC.Exts (Addr#, Int#, copyAddrToByteArray#, newByteArray#, unsafeFreezeByteArray#)+import GHC.ST (ST(..))+import Polytropos.Core (Rep(..), Row, RowRep(..), RowType(..))++-- | Promoted algebra selector for Skew Boolean Intersection operations on rows.+data MergeOp+ = OpOverrideR+ | OpOverrideL+ | OpDisjoint+ | OpReplace+ | OpRestrict+ | OpDiff+ | OpSymDiff+ deriving (Eq, Ord, Show)++-- | Unboxed gather plan mapping each slot of 'rOut' to either 'r1' (k >= 0)+-- or 'r2' (k < 0, reading slot 'complement k').+newtype MergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row) =+ MergeMorph { unMergeMorph :: PrimArray Int }+ deriving (Eq, Show)++-- | Solved automatically by Polytropos.Plugin in O(|r1| + |r2|) compile time.+class KnownMergeMorph (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row)+ | op r1 r2 -> rOut where+ mergeMorph :: MergeMorph op r1 r2 rOut++-- | Execute any binary Skew Boolean record operation in a single allocation pass.+{-# INLINE executeMergeMorph #-}+executeMergeMorph+ :: MergeMorph op r1 r2 rOut+ -> RowRep f tag1 r1 ()+ -> RowRep f tag2 r2 ()+ -> RowRep f ProductRowT rOut ()+executeMergeMorph (MergeMorph plan) (RowRep (Rep _ arr1)) (RowRep (Rep _ arr2)) =+ let !nOut = sizeofPrimArray plan+ in RowRep $ Rep 0 $ runSmallArray $ do+ out <- newSmallArray nOut (error "Polytropos.MergeMorph: uninitialized slot")+ let go !i+ | i >= nOut = pure out+ | otherwise = do+ let !code = indexPrimArray plan i+ !val = if code >= 0+ then indexSmallArray arr1 code+ else indexSmallArray arr2 (complement code)+ writeSmallArray out i val+ go (i + 1)+ go 0++-- | Core synthesis target: materializes a 'MergeMorph' from an index list.+{-# NOINLINE unsafeMkMergeMorph #-}+unsafeMkMergeMorph :: forall (op :: MergeOp) (r1 :: Row) (r2 :: Row) (rOut :: Row). [Int] -> MergeMorph op r1 r2 rOut+unsafeMkMergeMorph idxs = MergeMorph (primArrayFromList idxs)++-- | Core synthesis target: materializes a 'MergeMorph' from a static .rodata 'Addr#'.+{-# INLINE unsafeMkMergeMorph# #-}+unsafeMkMergeMorph# :: Int# -> Addr# -> MergeMorph op r1 r2 rOut+unsafeMkMergeMorph# nBytes# addr# = runST $ ST $ \s0 ->+ case newByteArray# nBytes# s0 of+ (# s1, mba# #) ->+ case copyAddrToByteArray# addr# mba# 0# nBytes# s1 of+ s2 ->+ case unsafeFreezeByteArray# mba# s2 of+ (# s3, ba# #) -> (# s3, MergeMorph (PrimArray ba#) #)++infixl 6 //>, <//, <+>, //~+infixl 7 |<, /-/, \^/++-- | Right-biased override (Right Skew Join): fields in 'r2' shadow 'r1'.+{-# INLINE (//>) #-}+(//>) :: forall r1 r2 rOut f tag1 tag2. KnownMergeMorph 'OpOverrideR r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f ProductRowT rOut ()+(//>) = executeMergeMorph (mergeMorph @'OpOverrideR @r1 @r2 @rOut)++-- | Left-biased override (Left Skew Join): fields in 'r1' shadow 'r2'.+{-# INLINE (<//) #-}+(<//) :: forall r1 r2 rOut f tag1 tag2. KnownMergeMorph 'OpOverrideL r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f ProductRowT rOut ()+(<//) = executeMergeMorph (mergeMorph @'OpOverrideL @r1 @r2 @rOut)++-- | Disjoint separating product: fails at compile time if 'r1' and 'r2' share labels.+{-# INLINE (<+>) #-}+(<+>) :: forall r1 r2 rOut f tag1 tag2. KnownMergeMorph 'OpDisjoint r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f ProductRowT rOut ()+(<+>) = executeMergeMorph (mergeMorph @'OpDisjoint @r1 @r2 @rOut)++-- | In-place subset update: overwrites 'r1' fields using 'r2' (r2 must be a sub-row of r1).+{-# INLINE (//~) #-}+(//~) :: forall r1 r2 f tag1 tag2. KnownMergeMorph 'OpReplace r1 r2 r1+ => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f ProductRowT r1 ()+(//~) = executeMergeMorph (mergeMorph @'OpReplace @r1 @r2 @r1)++-- | Domain restriction: keeps only fields of 'r1' whose labels occur in 'r2'.+{-# INLINE (|<) #-}+(|<) :: forall r1 r2 rOut f g tag1 tag2. KnownMergeMorph 'OpRestrict r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f ProductRowT rOut ()+r1 |< _ = executeMergeMorph (mergeMorph @'OpRestrict @r1 @r2 @rOut) r1 (RowRep (Rep 0 (runSmallArray (newSmallArray 0 (error "empty")))))++-- | Domain anti-restriction (relative complement): drops from 'r1' any label in 'r2'.+{-# INLINE (/-/) #-}+(/-/) :: forall r1 r2 rOut f g tag1 tag2. KnownMergeMorph 'OpDiff r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep g tag2 r2 () -> RowRep f ProductRowT rOut ()+r1 /-/ _ = executeMergeMorph (mergeMorph @'OpDiff @r1 @r2 @rOut) r1 (RowRep (Rep 0 (runSmallArray (newSmallArray 0 (error "empty")))))++-- | Symmetric difference: keeps fields present in exactly one of 'r1' or 'r2'.+{-# INLINE (\^/) #-}+(\^/) :: forall r1 r2 rOut f tag1 tag2. KnownMergeMorph 'OpSymDiff r1 r2 rOut+ => RowRep f tag1 r1 () -> RowRep f tag2 r2 () -> RowRep f ProductRowT rOut ()+(\^/) = executeMergeMorph (mergeMorph @'OpSymDiff @r1 @r2 @rOut)
+ src/Polytropos/Record.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE RoleAnnotations #-}++-- |+-- Module : Polytropos.Record+-- Description : Reified Record wrapper and Skew Boolean re-exports+module Polytropos.Record+ ( Record+ , RecordF+ , RowRep(..)+ , emptyRecord+ , emptyRecordF+ , (//>)+ , (<//)+ , (<+>)+ , (//~)+ , (|<)+ , (/-/)+ , (\^/)+ ) where++import Polytropos (Record, RecordF, emptyRecord, emptyRecordF)+import Polytropos.Core (RowRep(..))+import Polytropos.MergeMorph
src/Polytropos/RowMorph.hs view
@@ -18,30 +18,30 @@ 2. Inductive type-level searches (@KnownNat@ / inductive dictionary trees) that generate \(O(N)\) or \(O(N^2)\) pointer-chasing calls at runtime. -'RowMorph' collapses row routing and projection into a single unboxed 'PrimArray' 'Int'+'t:RowMorph' collapses row routing and projection into a single unboxed 'PrimArray' 'Int' (backed by a contiguous 'GHC.Exts.ByteArray#' primitive). Each index @i@ in @[0 .. |r1| - 1]@ contains the literal 0-based slot offset in the target row @r2@. == Key Features & Operations -* __Unboxed Reification:__ 'RowMorph' has zero heap allocation overhead per element, storing+* __Unboxed Reification:__ 't:RowMorph' has zero heap allocation overhead per element, storing pure integer indices densely in cache lines. * __\(O(|r1|)\) Category Composition:__ 'composeRowMorph' composes two morphisms in a single branchless pass, computing @m23(m12(i))@ into a newly allocated 'PrimArray' without intermediate lists. * __Contravariant Reduct Gather:__ 'gatherRep' extracts an arbitrary subrow or permutation from- an existing 'Polytropos.Core.Rep' in \(O(|sub|)\) time with a single 'Data.Primitive.SmallArray.SmallArray' allocation.-* __In-Place Scatter:__ 'scatterRep' writes back updated subrow slots into an existing 'Rep'+ an existing 't:Polytropos.Core.Rep' in \(O(|sub|)\) time with a single 't:Data.Primitive.SmallArray.SmallArray' allocation.+* __In-Place Scatter:__ 'scatterRep' writes back updated subrow slots into an existing 't:Rep' in \(O(|full|)\) time via 'Data.Primitive.SmallArray.thawSmallArray'. * __Compile-Time Synthesis:__ The evidence class 'KnownRowMorph' is solved directly by @Polytropos.Plugin@, emitting literal index vectors into Core AST with zero runtime dictionary search.-* __Frame-Rule Auto-Wiring:__ 'FramePlan' and 'FrameWire' generalize binary port routing+* __Frame-Rule Auto-Wiring:__ 't:FramePlan' and 'FrameWire' generalize binary port routing to stateful execution frames with automatic output row synthesis (see Note [Frame-Rule Automatic Wire Synthesis] [ref:note-frame-rule-wiring]). = Note [Reified Row Morphisms and Gather-Scatter] [tag:note-row-morph-routing] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A row morphism @RowMorph r1 r2@ models a structural embedding / projection map from @r1@ into @r2@. Rather than representing morphisms as functions @Record r2 -> Record r1@ or type-level inductive-witnesses, 'RowMorph' reifies the mapping as a flat primitive array of integers.+witnesses, 't:RowMorph' reifies the mapping as a flat primitive array of integers. 1. Category Structure: - Identity: @idMorph = RowMorph [0, 1, .. n-1]@.@@ -54,7 +54,7 @@ exactly the active ports or handler methods into a compact, contiguous memory buffer. 3. Frame-Rule Auto-Wiring:- 'FramePlan' and 'FrameWire' generalize binary port routing to stateful execution frames:+ 't:FramePlan' and 'FrameWire' generalize binary port routing to stateful execution frames: an operation @(opIn -> opOut)@ inside @(frameIn -> frameOut)@ executes by gathering @opIn@ from @frameIn@, copying surviving @frameIn@ slots to @frameOut@, and scattering @opOut@ into @frameOut@ in two tight branchless loops.@@ -76,7 +76,7 @@ -> p (Record frameIn) (Record frameOut) 1. Dual Gather-Scatter Lifecycle:- Execution proceeds in two phases coordinated by 'FramePlan':+ Execution proceeds in two phases coordinated by 't:FramePlan': a. Contravariant Port Gather: Before the operation runs, its input ports @opIn@ are gathered from @frameIn@ via @fpGatherIn :: RowMorph opIn frameIn@.@@ -136,11 +136,23 @@ , FrameWire(..) , unsafeMkFramePlan , executeFrameScatter+ -- * 2LTT Static Layout Descriptors+ , SlotIndex(..)+ , RowLayoutDescriptorOf(..)+ , RowLayoutDescriptor+ , buildRowLayoutDescriptor+ , resolveRowSlot ) where import Control.Monad.ST ( runST )+import Data.List+ ( sort+ )+import GHC.Generics+ ( Generic+ ) import Data.Kind ( Constraint , Type@@ -183,7 +195,7 @@ { unRowMorph :: PrimArray Int } deriving stock (Eq, Show) --- | Solved by @Polytropos.Plugin@ into a static 'RowMorph' CAF constant.+-- | Solved by @Polytropos.Plugin@ into a static 't:RowMorph' CAF constant. -- -- When @r1@ is a subrow or permutation of @r2@, the compiler plugin synthesizes -- the literal permutation array and emits the instance dictionary directly into Core AST.@@ -203,7 +215,7 @@ {-# INLINE indexRowMorph #-} indexRowMorph (RowMorph arr) !i = indexPrimArray arr i --- | Category composition for 'RowMorph': \(\mathcal{O}(|r1|)\) primitive array indexing.+-- | Category composition for 't:RowMorph': \(\mathcal{O}(|r1|)\) primitive array indexing. -- -- Given morphisms @m12 : r1 -> r2@ and @m23 : r2 -> r3@, computes @m13 : r1 -> r3@ -- where each slot @i@ in @r1@ maps to @m23(m12(i))@ in @r3@.@@ -230,7 +242,7 @@ -- | Contravariant reduct / port gather: extracts @sub@ slots from @full@ in \(\mathcal{O}(|sub|)\). -- -- Directly implements \(\mathrm{Mod}(\sigma)(M')\) for handler records, input port frames,--- and structural subrow extraction with a single 'SmallArray' allocation.+-- and structural subrow extraction with a single 't:Data.Primitive.SmallArray.SmallArray' allocation. -- -- See Note [Reified Row Morphisms and Gather-Scatter] [ref:note-row-morph-routing] gatherRep :: RowMorph sub full -> Rep f a -> Rep f b@@ -288,7 +300,7 @@ -- | Solved by @Polytropos.Plugin@: -- 1. Verifies @opIn@ is a subrow of @frameIn@ (unifying port types). -- 2. Synthesizes @frameOut ~ RowOverwrite frameIn opOut@.--- 3. Emits the 'FramePlan' dictionary.+-- 3. Emits the 't:FramePlan' dictionary. -- -- See Note [Frame-Rule Automatic Wire Synthesis] [ref:note-frame-rule-wiring] type FrameWire :: forall {k1} {k2} {k3} {k4}. k1 -> k2 -> k3 -> k4 -> Constraint@@ -342,3 +354,42 @@ copyOp (j + 1) copyBase 0 copyOp 0++{-------------------------------------------------------------------------------+ 2LTT Static Layout Descriptors+-------------------------------------------------------------------------------}++-- | 2LTT slot reference: either statically resolved or accessed via open row tail evidence.+data SlotIndex+ = StaticSlot !Int+ | OpenTailSlot !String !String -- ^ (Row variable @rho@, Field/Tag label @l@)+ deriving stock (Eq, Ord, Show, Generic)++-- | 2LTT static layout descriptor: canonical 0-indexed static slot map for target lowering+-- (OrganIR / GIMPLE / MLIR / C struct offsets) versus SmallArray# host evaluation.+data RowLayoutDescriptorOf s = RowLayoutDescriptor+ { rldKnownSlots :: ![(String, Int)]+ -- ^ Canonical lexicographical slot offsets into Polytropos 'Rep' SmallArray+ , rldKnownSorts :: ![(String, s)]+ , rldOpenTail :: !(Maybe String)+ } deriving stock (Eq, Show, Generic)++type RowLayoutDescriptor = RowLayoutDescriptorOf String++-- | Compiles a list of field labels to a canonical 0-indexed static slot table.+buildRowLayoutDescriptor :: [String] -> Maybe String -> RowLayoutDescriptor+buildRowLayoutDescriptor fields mTail =+ let sortedFields = sort fields+ slots = zip sortedFields [0..]+ in RowLayoutDescriptor+ { rldKnownSlots = slots+ , rldKnownSorts = []+ , rldOpenTail = mTail+ }++-- | Resolve a label to a static slot index or an open tail slot.+resolveRowSlot :: RowLayoutDescriptorOf s -> String -> SlotIndex+resolveRowSlot rld lbl =+ case lookup lbl (rldKnownSlots rld) of+ Just idx -> StaticSlot idx+ Nothing -> OpenTailSlot (maybe "rho_default" id (rldOpenTail rld)) lbl
test/Main.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -26,10 +27,14 @@ module Main (main) where import Control.Monad.ST (runST)+import Data.Bits (complement)+import Data.Functor.Compose (Compose(..))+import Data.Functor.Const (Const(..)) import Data.Functor.Identity (Identity(..)) import Data.Kind (Type)-import Data.Primitive.PrimArray (sizeofPrimArray)+import Data.Primitive.PrimArray (primArrayFromList, sizeofPrimArray) import Data.Primitive.SmallArray (indexSmallArray)+import Data.Proxy (Proxy(..)) import GHC.Exts (Any) import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.HUnit (testCase, (@?=))@@ -124,6 +129,16 @@ && repArity r1 == repArity r2 && intAt0 r1 == intAt0 r2 +instance AllFields ProductRowT R2 Top where+ fieldDicts = evidenceAllFields [mkDictAny @Top @Int, mkDictAny @Top @Bool]++instance AllFields ProductRowT R2 Show where+ fieldDicts = evidenceAllFields [mkDictAny @Show @Int, mkDictAny @Show @Bool]++-- | Hand-written SubRow witness for testing (sub :- super).+instance SubRow '[ "a" := Int ] R2 where+ subRowIndices = [0]+ {------------------------------------------------------------------------------- Fixtures -------------------------------------------------------------------------------}@@ -268,6 +283,9 @@ instance ConstructorIndex "Neg" '[ "Neg" ':= '[ "v" ':= Int ] ] where constructorIndex = 0 +instance AllFields SumRowT TwoSum Show where+ fieldDicts = evidenceAllFields [mkDictAny @Show @Int, mkDictAny @Show @Int]+ consumerTests :: TestTree consumerTests = testGroup "consumer api (Polytropos)" [ testCase "emptyRecord has arity 0" $@@ -502,6 +520,25 @@ unslot (fieldAt 0 (unRowRep fOut)) @?= (1 :: Int) unslot (fieldAt 1 (unRowRep fOut)) @?= ("new" :: String) unslot (fieldAt 2 (unRowRep fOut)) @?= True++ , testCase "SubRow (:-) constraint alias witnesses sub-row projection" $ do+ let witnessSubRow :: forall sub super. (sub :- super) => [Int]+ witnessSubRow = subRowIndices @sub @super+ witnessSubRow @('[ "a" := Int ]) @R2 @?= [0]++ , testCase "RowLayoutDescriptor 2LTT static layout and slot resolution" $ do+ let rldClosed = buildRowLayoutDescriptor ["delta", "alpha", "gamma", "beta"] Nothing+ rldKnownSlots rldClosed @?= [("alpha", 0), ("beta", 1), ("delta", 2), ("gamma", 3)]+ rldOpenTail rldClosed @?= Nothing+ resolveRowSlot rldClosed "beta" @?= StaticSlot 1+ resolveRowSlot rldClosed "gamma" @?= StaticSlot 3+ resolveRowSlot rldClosed "omega" @?= OpenTailSlot "rho_default" "omega"++ let rldOpen = buildRowLayoutDescriptor ["y", "x"] (Just "rho_tail")+ rldKnownSlots rldOpen @?= [("x", 0), ("y", 1)]+ rldOpenTail rldOpen @?= Just "rho_tail"+ resolveRowSlot rldOpen "x" @?= StaticSlot 0+ resolveRowSlot rldOpen "z" @?= OpenTailSlot "rho_tail" "z" ] -- | Mock higher-kinded effect signatures for EffectRowOf testing.@@ -533,6 +570,247 @@ constructorIndex @_ @"log" @MyCoreEf @?= 1 ] +sopTests :: TestTree+sopTests = testGroup "sop combinators (Polytropos.Core.SOP)"+ [ testCase "hcollapse extracts values from Const-wrapped product RowRep" $ do+ let r = RowRep (productRep [Const (10 :: Int), Const (20 :: Int)]) :: RowRep (Const Int) ProductRowT R2 ()+ hcollapse r @?= [10, 20]+ hcollapseFold r @?= [10, 20]++ , testCase "hcollapse extracts active constructor payload from Const-wrapped sum RowRep" $ do+ let s = RowRep (injectRep 1 [Const (42 :: Int)]) :: RowRep (Const Int) SumRowT TwoSum ()+ hcollapse s @?= [42]+ hcollapseFold s @?= [42]++ , testCase "hpure populates product RowRep using Top constraint" $ do+ let p = hpure @R2 (Const (99 :: Int))+ hcollapse p @?= [99, 99]++ , testCase "hpureFromNames populates product RowRep using ReifyFieldNames" $ do+ let p = hpureFromNames @R2 (Const (123 :: Int))+ hcollapse p @?= [123, 123]++ , testCase "hpureArity populates product RowRep with specified length" $ do+ let p = hpureArity 4 (Const ("ok" :: String)) :: RowRep (Const String) ProductRowT R2 ()+ hcollapse p @?= ["ok", "ok", "ok", "ok"]++ , testCase "hcpure populates product RowRep using class constraint" $ do+ let cp = hcpure @Show @R2 (Const ("shown" :: String))+ hcollapse cp @?= ["shown", "shown"]+ let cp_ = hcpure_ (Proxy @Show) (Const ("proxy" :: String)) :: RowRep (Const String) ProductRowT R2 ()+ hcollapse cp_ @?= ["proxy", "proxy"]++ , testCase "hmap and hliftA preserve tag and map over slots" $ do+ let p = RowRep (productRep [slot (1 :: Int), slot (2 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ p' = hmap (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + 10))) p+ unslot (fieldAt 0 (unRowRep p')) @?= (11 :: Int)+ unslot (fieldAt 1 (unRowRep p')) @?= (12 :: Int)++ let s = RowRep (injectRep 1 [slot (5 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ s' = hliftA (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) * 3))) s+ repTag (unRowRep s') @?= 1+ unslot (fieldAt 0 (unRowRep s')) @?= (15 :: Int)++ , testCase "hcmapProduct and hcmapSum apply constrained mapping" $ do+ let p = RowRep (productRep [slot (10 :: Int), slot True]) :: RowRep Identity ProductRowT R2 ()+ shownP = hcmapProduct @Show (\(Identity x) -> Const (show x)) p+ case hcollapse shownP of+ [s0, _] -> s0 @?= "10"+ _ -> error "Expected 2 items"++ let s = RowRep (injectRep 1 [slot (99 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ shownS = hcmapSum @Show (\(Identity x) -> Const (show x)) s+ hcollapse shownS @?= ["99"]++ let uP = hcmap @Show (\(Const str) -> Const (str ++ "!")) shownP+ case hcollapse uP of+ (s0 : _) -> s0 @?= "10!"+ [] -> error "Expected non-empty list"+ let uS = hcmap @Show (\(Const str) -> Const (str ++ "!")) shownS+ hcollapse uS @?= ["99!"]++ , testCase "hliftA2 and hzipWith pointwise zip product rows" $ do+ let p1 = RowRep (productRep [slot (1 :: Int), slot (2 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ p2 = RowRep (productRep [slot (10 :: Int), slot (20 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ z = hliftA2 (\(Identity x) (Identity y) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + (noInlineUnsafeCo y :: Int)))) p1 p2+ unslot (fieldAt 0 (unRowRep z)) @?= (11 :: Int)+ unslot (fieldAt 1 (unRowRep z)) @?= (22 :: Int)++ , testCase "hliftA2Sum succeeds on matching tags and fails on mismatched tags" $ do+ let s1 = RowRep (injectRep 1 [slot (5 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ s2 = RowRep (injectRep 1 [slot (10 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ sDiff = RowRep (injectRep 0 [slot (10 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ zMatch = hliftA2Sum (\(Identity x) (Identity y) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + (noInlineUnsafeCo y :: Int)))) s1 s2+ case zMatch of+ Just (RowRep r) -> do+ repTag r @?= 1+ unslot (fieldAt 0 r) @?= (15 :: Int)+ Nothing -> error "Expected Just for matching tags"++ let zMismatch = hliftA2Sum (\(Identity x) (Identity y) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + (noInlineUnsafeCo y :: Int)))) s1 sDiff+ case zMismatch of+ Nothing -> pure ()+ Just _ -> error "Expected Nothing for mismatched tags"++ , testCase "hcliftA2 and hczipWith apply constrained binary zip" $ do+ let p1 = RowRep (productRep [slot (1 :: Int), slot True]) :: RowRep Identity ProductRowT R2 ()+ p2 = RowRep (productRep [slot (3 :: Int), slot False]) :: RowRep Identity ProductRowT R2 ()+ cz = hcliftA2 @Show (\(Identity x) (Identity y) -> Const (show x ++ "+" ++ show y)) p1 p2+ hcollapse cz @?= ["1+3", "True+False"]++ , testCase "hliftA3 and hcliftA3 3-way zip product rows" $ do+ let p1 = RowRep (productRep [slot (1 :: Int), slot (2 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ p2 = RowRep (productRep [slot (10 :: Int), slot (20 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ p3 = RowRep (productRep [slot (100 :: Int), slot (200 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ z3 = hliftA3 (\(Identity x) (Identity y) (Identity z) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + (noInlineUnsafeCo y :: Int) + (noInlineUnsafeCo z :: Int)))) p1 p2 p3+ unslot (fieldAt 0 (unRowRep z3)) @?= (111 :: Int)+ unslot (fieldAt 1 (unRowRep z3)) @?= (222 :: Int)++ , testCase "hproduct and hunzip roundtrip in single ST pass" $ do+ let p1 = RowRep (productRep [slot (1 :: Int), slot (2 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ p2 = RowRep (productRep [slot ("hello" :: String), slot ("world" :: String)]) :: RowRep Identity ProductRowT R2 ()+ prod = hproduct p1 p2+ (u1, u2) = hunzip prod+ unslot (fieldAt 0 (unRowRep u1)) @?= (1 :: Int)+ unslot (fieldAt 1 (unRowRep u1)) @?= (2 :: Int)+ unslot (fieldAt 0 (unRowRep u2)) @?= ("hello" :: String)+ unslot (fieldAt 1 (unRowRep u2)) @?= ("world" :: String)++ , testCase "hapProduct applies product of functions to product of values" $ do+ let fn1 = Fn (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) * 2)))+ fn2 = Fn (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) * 10)))+ fns = RowRep (productRep [noInlineUnsafeCo fn1, noInlineUnsafeCo fn2])+ :: RowRep (Identity -.-> Identity) ProductRowT R2 ()+ args = RowRep (productRep [slot (5 :: Int), slot (6 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ res = hapProduct fns args+ unslot (fieldAt 0 (unRowRep res)) @?= (10 :: Int)+ unslot (fieldAt 1 (unRowRep res)) @?= (60 :: Int)++ , testCase "hapSum dispatches product of functions to sum in O(1)" $ do+ let fn1 = Fn (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) * 2)))+ fn2 = Fn (\(Identity x) -> Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) * 10)))+ fns = RowRep (productRep [noInlineUnsafeCo fn1, noInlineUnsafeCo fn2])+ :: RowRep (Identity -.-> Identity) ProductRowT TwoSum ()+ argS0 = RowRep (injectRep 0 [slot (7 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ argS1 = RowRep (injectRep 1 [slot (7 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ res0 = hapSum fns argS0+ res1 = hapSum fns argS1+ repTag (unRowRep res0) @?= 0+ unslot (fieldAt 0 (unRowRep res0)) @?= (14 :: Int)+ repTag (unRowRep res1) @?= 1+ unslot (fieldAt 0 (unRowRep res1)) @?= (70 :: Int)++ , testCase "helim eliminates sum variant using handler product in O(1)" $ do+ let h1 = Fn (\(Identity x) -> Const (-(noInlineUnsafeCo x :: Int)))+ h2 = Fn (\(Identity x) -> Const ((noInlineUnsafeCo x :: Int) * 100))+ handlers = RowRep (productRep [noInlineUnsafeCo h1, noInlineUnsafeCo h2])+ :: RowRep (Identity -.-> Const Int) ProductRowT TwoSum ()+ argS0 = RowRep (injectRep 0 [slot (8 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ argS1 = RowRep (injectRep 1 [slot (8 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ helim handlers argS0 @?= (-8)+ helim handlers argS1 @?= 800++ , testCase "hfoldMap and hcfoldMap accumulate into monoid" $ do+ let p = RowRep (productRep [slot (1 :: Int), slot True]) :: RowRep Identity ProductRowT R2 ()+ res = hfoldMap (\(Identity _) -> [1 :: Int]) p+ res @?= [1, 1]+ let cfm = hcfoldMap @Show (\(Identity x) -> [show x]) p+ cfm @?= ["1", "True"]++ , testCase "hcfoldMapSum accumulates active constructor into monoid" $ do+ let s = RowRep (injectRep 1 [slot (42 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ res = hcfoldMapSum @Show (\(Identity x) -> [show x]) s+ res @?= ["42"]++ , testCase "hsequence' and hsequence sequence Applicative effects" $ do+ let compP = RowRep (productRep [Compose (Just (slot (10 :: Int))), Compose (Just (slot (20 :: Int)))])+ :: RowRep (Compose Maybe Identity) ProductRowT R2 ()+ case hsequence' compP of+ Just r -> do+ unslot (fieldAt 0 (unRowRep r)) @?= (10 :: Int)+ unslot (fieldAt 1 (unRowRep r)) @?= (20 :: Int)+ Nothing -> error "Expected Just"++ let seqP = RowRep (productRep [Just (noInlineUnsafeCo (10 :: Int)), Just (noInlineUnsafeCo (20 :: Int))])+ :: RowRep Maybe ProductRowT R2 ()+ case hsequence seqP of+ Just r -> do+ unslot (fieldAt 0 (unRowRep r)) @?= (10 :: Int)+ unslot (fieldAt 1 (unRowRep r)) @?= (20 :: Int)+ Nothing -> error "Expected Just"++ , testCase "htraverse and hctraverse traverse Applicative effects" $ do+ let p = RowRep (productRep [slot (1 :: Int), slot (2 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ tRes = htraverse (\(Identity x) -> Just (Identity (noInlineUnsafeCo ((noInlineUnsafeCo x :: Int) + 1)))) p+ case tRes of+ Just r -> do+ unslot (fieldAt 0 (unRowRep r)) @?= (2 :: Int)+ unslot (fieldAt 1 (unRowRep r)) @?= (3 :: Int)+ Nothing -> error "Expected Just"++ , testCase "hindex returns active constructor index in O(1)" $ do+ let s0 = RowRep (injectRep 0 [slot (1 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ s1 = RowRep (injectRep 1 [slot (2 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ hindex s0 @?= 0+ hindex s1 @?= 1++ , testCase "hexpand expands sum into Compose Maybe product" $ do+ let s = RowRep (injectRep 1 [slot (99 :: Int)]) :: RowRep Identity SumRowT TwoSum ()+ expanded = hexpand @TwoSum s+ repArity (unRowRep expanded) @?= 2+ case fieldAt 0 (unRowRep expanded) of+ Compose Nothing -> pure ()+ _ -> error "Expected Nothing at slot 0"+ case fieldAt 1 (unRowRep expanded) of+ Compose (Just x) -> unslot x @?= (99 :: Int)+ _ -> error "Expected Just at slot 1"++ , testCase "injections and apInjs sum/product conversions" $ do+ let injs = injections @TwoSum :: RowRep (Identity -.-> Const (RowRep Identity SumRowT TwoSum ())) ProductRowT TwoSum ()+ repArity (unRowRep injs) @?= 2++ let p = RowRep (productRep [slot (10 :: Int), slot (20 :: Int)]) :: RowRep Identity ProductRowT TwoSum ()+ injsList = apInjs p+ case injsList of+ [inj0, inj1] -> do+ repTag (unRowRep inj0) @?= 0+ unslot (fieldAt 0 (unRowRep inj0)) @?= (10 :: Int)+ repTag (unRowRep inj1) @?= 1+ unslot (fieldAt 0 (unRowRep inj1)) @?= (20 :: Int)+ _ -> error "Expected 2 injections"++ , testCase "hhead extracts slot 0" $ do+ let p = RowRep (productRep [slot (77 :: Int), slot (88 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ unslot (hhead p) @?= (77 :: Int)++ , testCase "hcoerce, htoI, hfromI perform zero-copy casts" $ do+ let p = RowRep (productRep [slot (42 :: Int)]) :: RowRep Identity ProductRowT R2 ()+ asI = htoI p+ unI (unslot (fieldAt 0 (unRowRep asI))) @?= (42 :: Int)+ let asId :: RowRep Identity ProductRowT R2 ()+ asId = hfromI asI+ runIdentity (unslot (fieldAt 0 (unRowRep asId))) @?= (42 :: Int)++ , testCase "hfieldNames reifies row symbol names" $ do+ let namesR2 = hfieldNames @R2 :: RowRep (Const String) ProductRowT R2 ()+ hcollapse namesR2 @?= ["a", "b"]+ let namesTwoSum = hfieldNames @TwoSum :: RowRep (Const String) ProductRowT TwoSum ()+ hcollapse namesTwoSum @?= ["Neg", "Pos"]++ , testCase "htoRecord, hfromRecord, htoVariant, hfromVariant bridge facade" $ do+ let p = RowRep (productRep [slot (100 :: Int)]) :: RowRep Identity ProductRowT R2 Int+ recVal = htoRecord p+ repArity (unRowRep recVal) @?= 1+ let p' = hfromRecord recVal :: RowRep Identity ProductRowT R2 Int+ repArity (unRowRep p') @?= 1++ let s = RowRep (injectRep 1 [slot (200 :: Int)]) :: RowRep Identity SumRowT TwoSum Int+ varVal = htoVariant s+ repTag (unRowRep varVal) @?= 1+ let s' = hfromVariant varVal :: RowRep Identity SumRowT TwoSum Int+ repTag (unRowRep s') @?= 1+ ]+ main :: IO () main = defaultMain $ testGroup "polytropos-core" [ productTests@@ -542,4 +820,18 @@ , simdTests , rowMorphTests , effectRowTests+ , sopTests+ , mergeMorphTests+ ]++mergeMorphTests :: TestTree+mergeMorphTests = testGroup "merge-morph"+ [ testCase "executeMergeMorph with two's-complement gather plan" $ do+ let plan = MergeMorph (primArrayFromList [0, complement 0]) :: MergeMorph 'OpOverrideR R2 R2 R2+ r1 = RowRep (productRep [slot (10 :: Int), slot (20 :: Int)])+ r2 = RowRep (productRep [slot (30 :: Int)])+ out = executeMergeMorph plan r1 r2+ repArity (unRowRep out) @?= 2+ (noInlineUnsafeCo (indexSmallArray (repVals (unRowRep out)) 0) :: Int) @?= (10 :: Int)+ (noInlineUnsafeCo (indexSmallArray (repVals (unRowRep out)) 1) :: Int) @?= (30 :: Int) ]