| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.ZipMatchK.Generic
Contents
Synopsis
- class ZipMatchK (f :: k) where
- class ZipMatchFoldK (f :: k) where
- genericZipMatchFoldK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k) m. (GenericK f, GZipMatchFold (RepK f), Monoid m) => Folds m as bs -> (f :@@: as) -> (f :@@: bs) -> Maybe m
- genericZipMatchK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k). (GenericK f, GZipMatch (RepK f), ReqsZipMatch (RepK f) as bs, PairMappings as bs) => (f :@@: as) -> (f :@@: bs) -> Maybe (f :@@: ZipLoT as bs)
- genericZipMatchWithK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k) (cs :: LoT k). (GenericK f, GZipMatch (RepK f), ReqsZipMatchWith (RepK f) as bs cs) => Mappings as bs cs -> (f :@@: as) -> (f :@@: bs) -> Maybe (f :@@: cs)
- type ReqsZipMatch (f :: LoT k -> Type) (as :: LoT k) (bs :: LoT k) = ReqsZipMatchWith f as bs (ZipLoT as bs)
- class GZipMatch (f :: LoT k -> Type) where
- type ReqsZipMatchWith (f :: LoT k -> Type) (as :: LoT k) (bs :: LoT k) (cs :: LoT k)
- gzipMatchWith :: forall (as :: LoT k) (bs :: LoT k) (cs :: LoT k). ReqsZipMatchWith f as bs cs => Mappings as bs cs -> f as -> f bs -> Maybe (f cs)
- class ZipMatchFields (t :: Atom d Type) where
- class GZipMatchFold (f :: LoT k -> Type) where
- class ZipMatchFieldsFold (t :: Atom d Type) where
Documentation
class ZipMatchK (f :: k) where Source #
Kind-polymorphic syntactic (first-order) unification of two values.
Note that f is expected to be a traversable n-functor. There is no
TraversableK constraint to say so at the moment.
The default implementation is generic, via RepK. It is
convenient, but it reflects each node into a representation and back on
every comparison, and a constructor is represented as a chain of
L1/R1 wrappers as long as its index, so the cost grows with the size of
the signature. Comparing terms is most of what a typechecker does, and on a
large signature the generic instance costs roughly twice what the
written-out one does. Use deriveZipMatchK (or
deriveZipMatchK2, for a signature bifunctor with extra
parameters) to generate the written-out instance instead.
Since: 0.2.0
Minimal complete definition
Nothing
Methods
zipMatchWithK :: forall (as :: LoT k) (bs :: LoT k) (cs :: LoT k). Mappings as bs cs -> (f :@@: as) -> (f :@@: bs) -> Maybe (f :@@: cs) Source #
Instances
| ZipMatchK Either Source # | |
| ZipMatchK (,) Source # | |
| ZipMatchK NonEmpty Source # | |
| ZipMatchK Maybe Source # | |
| ZipMatchK [] Source # | |
| ZipMatchK a => ZipMatchK (Either a :: Type -> Type) Source # | |
| ZipMatchK a => ZipMatchK ((,) a :: Type -> Type) Source # | |
| (ZipMatchK ann, ZipMatchK sig) => ZipMatchK (AnnSig ann sig :: Type -> Type -> Type) Source # | |
| (ZipMatchK f, ZipMatchK g) => ZipMatchK (Product f g :: Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchK f, ZipMatchK g) => ZipMatchK (Sum f g :: Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchK f, ZipMatchK g) => ZipMatchK (Product f g :: Type -> Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchK f, ZipMatchK g) => ZipMatchK (Sum f g :: Type -> Type -> Type) Source # | Note: instance is limited to |
class ZipMatchFoldK (f :: k) where Source #
Kind-polymorphic syntactic matching of two values that folds the paired components into a monoid instead of rebuilding the value.
zipMatchFoldK answers Nothing exactly when zipMatchWithK with
functions that always succeed would: when the constructors differ, or a
component compared by its own ZipMatchK differs. Otherwise it combines
the folding functions applied to the paired components, left to right with
<>. Nothing else is built, neither the matched value nor a pair per
component, so a check of all components (with All, say)
allocates nothing for the components and stops at the first one that
fails.
The default implementation is generic, via RepK, with the
costs described at ZipMatchK. deriveZipMatchK derives
a written-out instance together with the one of ZipMatchK.
Since: 0.6.0
Minimal complete definition
Nothing
Methods
zipMatchFoldK :: forall (as :: LoT k) (bs :: LoT k) m. Monoid m => Folds m as bs -> (f :@@: as) -> (f :@@: bs) -> Maybe m Source #
Perform one level of equality testing and fold the paired components.
Since: 0.6.0
Instances
| ZipMatchFoldK Either Source # | |
| ZipMatchFoldK (,) Source # | |
| ZipMatchFoldK NonEmpty Source # | |
| ZipMatchFoldK Maybe Source # | |
| ZipMatchFoldK [] Source # | |
| ZipMatchK a => ZipMatchFoldK (Either a :: Type -> Type) Source # | |
| ZipMatchK a => ZipMatchFoldK ((,) a :: Type -> Type) Source # | |
| (ZipMatchFoldK ann, ZipMatchFoldK sig) => ZipMatchFoldK (AnnSig ann sig :: Type -> Type -> Type) Source # | Matching for The generic default would rebuild the Generics.Kind view of every node on
every comparison, and comparing terms is most of what a typechecker does, so
for an annotated signature, where it lands on the hottest path, that is a
measurable cost. |
| (ZipMatchFoldK f, ZipMatchFoldK g) => ZipMatchFoldK (Product f g :: Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchFoldK f, ZipMatchFoldK g) => ZipMatchFoldK (Sum f g :: Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchFoldK f, ZipMatchFoldK g) => ZipMatchFoldK (Product f g :: Type -> Type -> Type) Source # | Note: instance is limited to |
| (ZipMatchFoldK f, ZipMatchFoldK g) => ZipMatchFoldK (Sum f g :: Type -> Type -> Type) Source # | Note: instance is limited to |
genericZipMatchFoldK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k) m. (GenericK f, GZipMatchFold (RepK f), Monoid m) => Folds m as bs -> (f :@@: as) -> (f :@@: bs) -> Maybe m Source #
Generic implementation of zipMatchFoldK.
Since: 0.6.0
genericZipMatchK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k). (GenericK f, GZipMatch (RepK f), ReqsZipMatch (RepK f) as bs, PairMappings as bs) => (f :@@: as) -> (f :@@: bs) -> Maybe (f :@@: ZipLoT as bs) Source #
Generic implementation of zipMatchK.
Since: 0.2.0
genericZipMatchWithK :: forall {k} (f :: k) (as :: LoT k) (bs :: LoT k) (cs :: LoT k). (GenericK f, GZipMatch (RepK f), ReqsZipMatchWith (RepK f) as bs cs) => Mappings as bs cs -> (f :@@: as) -> (f :@@: bs) -> Maybe (f :@@: cs) Source #
Generic implementation of zipMatchWithK.
Since: 0.2.0
type ReqsZipMatch (f :: LoT k -> Type) (as :: LoT k) (bs :: LoT k) = ReqsZipMatchWith f as bs (ZipLoT as bs) Source #
What gzipMatchWith requires when the components are paired up.
Since: 0.2.0
class GZipMatch (f :: LoT k -> Type) where Source #
Matching on the Generics.Kind representation of a type, which is what
the default ZipMatchK instance goes through.
Since: 0.2.0
Associated Types
type ReqsZipMatchWith (f :: LoT k -> Type) (as :: LoT k) (bs :: LoT k) (cs :: LoT k) Source #
What matching this representation requires of its components.
Since: 0.2.0
Methods
gzipMatchWith :: forall (as :: LoT k) (bs :: LoT k) (cs :: LoT k). ReqsZipMatchWith f as bs cs => Mappings as bs cs -> f as -> f bs -> Maybe (f cs) Source #
Match two representations, pairing up their components with the given functions.
Since: 0.2.0
Instances
| GZipMatch (U1 :: LoT k -> Type) Source # | |
| GZipMatch (V1 :: LoT k -> Type) Source # | |
| ZipMatchFields t => GZipMatch (Field t :: LoT k -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| (GZipMatch f, GZipMatch g) => GZipMatch (f :*: g :: LoT k -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| (GZipMatch f, GZipMatch g) => GZipMatch (f :+: g :: LoT k -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| GZipMatch f => GZipMatch (c :=>: f :: LoT k -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| (TypeError ('Text "Existentials are not supported") :: Constraint) => GZipMatch (Exists k2 f :: LoT k1 -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| GZipMatch f => GZipMatch (M1 i c f :: LoT k -> Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
class ZipMatchFields (t :: Atom d Type) where Source #
Matching a single field of a constructor, by the shape of its type.
Since: 0.2.0
Associated Types
type ReqsZipMatchFieldsWith (t :: Atom d Type) (as :: LoT d) (bs :: LoT d) (cs :: LoT d) Source #
What matching this field requires.
Since: 0.2.0
Methods
zipMatchFieldsWith :: forall (as :: LoT d) (bs :: LoT d) (cs :: LoT d). ReqsZipMatchFieldsWith t as bs cs => Mappings as bs cs -> Field t as -> Field t bs -> Maybe (Field t cs) Source #
Match two fields, pairing up their contents.
Since: 0.2.0
Instances
| (TypeError (('Text "Atom :=>>: is not supported by ZipMatchFields" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType (c ':=>>: a)) :: Constraint) => ZipMatchFields (c ':=>>: a :: Atom d Type) Source # | |
| (TypeError (('Text "Atom Eval is not supported by ZipMatchFields" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType ('Eval a)) :: Constraint) => ZipMatchFields ('Eval a :: Atom d Type) Source # | |
| (TypeError (('Text "Atom ForAll is not supported by ZipMatchFields" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType ('ForAll a)) :: Constraint) => ZipMatchFields ('ForAll a :: Atom d Type) Source # | |
| ZipMatchK k => ZipMatchFields ('Kon k :: Atom d Type) Source # | |
Defined in Data.ZipMatchK.Generic | |
| ApplyMappings v => ZipMatchFields ('Var v :: Atom d Type) Source # | |
| (ZipMatchFields t1, ZipMatchFields t2, ZipMatchK k) => ZipMatchFields ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2 :: Atom d Type) Source # | |
Defined in Data.ZipMatchK.Generic Methods zipMatchFieldsWith :: forall (as :: LoT d) (bs :: LoT d) (cs :: LoT d). ReqsZipMatchFieldsWith ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2) as bs cs => Mappings as bs cs -> Field ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2) as -> Field ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2) bs -> Maybe (Field ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2) cs) Source # | |
| (ZipMatchFields t, ZipMatchK k) => ZipMatchFields (('Kon k :: Atom d (Type -> Type)) ':@: t :: Atom d Type) Source # | |
Defined in Data.ZipMatchK.Generic Methods zipMatchFieldsWith :: forall (as :: LoT d) (bs :: LoT d) (cs :: LoT d). ReqsZipMatchFieldsWith (('Kon k :: Atom d (Type -> Type)) ':@: t) as bs cs => Mappings as bs cs -> Field (('Kon k :: Atom d (Type -> Type)) ':@: t) as -> Field (('Kon k :: Atom d (Type -> Type)) ':@: t) bs -> Maybe (Field (('Kon k :: Atom d (Type -> Type)) ':@: t) cs) Source # | |
| (TypeError ((('Text "Atom :@: is not supported by ZipMatchFields is a general form:" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType (f ':@: t)) ':$$: (('ShowType f ':<>: 'Text " : ") ':<>: 'ShowType (Atom d (k1 -> Type)))) :: Constraint) => ZipMatchFields (f ':@: t :: Atom d Type) Source # | |
| (TypeError (((('Text "The type constructor is kind-polymorphic:" ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (kk -> Type))) ':$$: 'Text "Possible fix:") ':$$: 'Text " add an explicit kind signature") ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (Type -> Type))) :: Constraint) => ZipMatchFields (('Kon k :: Atom d (kk -> Type)) ':@: t :: Atom d Type) Source # | |
Defined in Data.ZipMatchK.Generic Methods zipMatchFieldsWith :: forall (as :: LoT d) (bs :: LoT d) (cs :: LoT d). ReqsZipMatchFieldsWith (('Kon k :: Atom d (kk -> Type)) ':@: t) as bs cs => Mappings as bs cs -> Field (('Kon k :: Atom d (kk -> Type)) ':@: t) as -> Field (('Kon k :: Atom d (kk -> Type)) ':@: t) bs -> Maybe (Field (('Kon k :: Atom d (kk -> Type)) ':@: t) cs) Source # | |
| (TypeError (((('Text "The type constructor is kind-polymorphic:" ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (kk1 -> kk2 -> Type))) ':$$: 'Text "Possible fix:") ':$$: 'Text " add an explicit kind signature") ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (Type -> Type -> Type))) :: Constraint) => ZipMatchFields ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2 :: Atom d Type) Source # | |
Defined in Data.ZipMatchK.Generic Methods zipMatchFieldsWith :: forall (as :: LoT d) (bs :: LoT d) (cs :: LoT d). ReqsZipMatchFieldsWith ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2) as bs cs => Mappings as bs cs -> Field ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2) as -> Field ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2) bs -> Maybe (Field ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2) cs) Source # | |
class GZipMatchFold (f :: LoT k -> Type) where Source #
Folding matches on the Generics.Kind representation of a type, which is
what the default ZipMatchFoldK instance goes through.
Since: 0.6.0
Methods
gzipMatchFold :: forall m (as :: LoT k) (bs :: LoT k). Monoid m => Folds m as bs -> f as -> f bs -> Maybe m Source #
Match two representations and fold their components with the given functions.
Since: 0.6.0
Instances
| GZipMatchFold (U1 :: LoT k -> Type) Source # | |
| GZipMatchFold (V1 :: LoT k -> Type) Source # | |
| ZipMatchFieldsFold t => GZipMatchFold (Field t :: LoT k -> Type) Source # | |
| (GZipMatchFold f, GZipMatchFold g) => GZipMatchFold (f :*: g :: LoT k -> Type) Source # | |
| (GZipMatchFold f, GZipMatchFold g) => GZipMatchFold (f :+: g :: LoT k -> Type) Source # | |
| GZipMatchFold f => GZipMatchFold (c :=>: f :: LoT k -> Type) Source # | |
| (TypeError ('Text "Existentials are not supported") :: Constraint) => GZipMatchFold (Exists k2 f :: LoT k1 -> Type) Source # | |
| GZipMatchFold f => GZipMatchFold (M1 i c f :: LoT k -> Type) Source # | |
class ZipMatchFieldsFold (t :: Atom d Type) where Source #
Folding matches of a single field of a constructor, by the shape of its
type. A field of a type that has no zipped parameter is compared by its
ZipMatchK and contributes mempty. A field of a type applied to zipped
parameters is folded by that type's ZipMatchFoldK.
Since: 0.6.0
Methods
zipMatchFieldsFold :: forall m (as :: LoT d) (bs :: LoT d). Monoid m => Folds m as bs -> Field t as -> Field t bs -> Maybe m Source #
Match two fields and fold their contents.
Since: 0.6.0
Instances
| (TypeError (('Text "Atom :=>>: is not supported by ZipMatchFieldsFold" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType (c ':=>>: a)) :: Constraint) => ZipMatchFieldsFold (c ':=>>: a :: Atom d Type) Source # | |
| (TypeError (('Text "Atom Eval is not supported by ZipMatchFieldsFold" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType ('Eval a)) :: Constraint) => ZipMatchFieldsFold ('Eval a :: Atom d Type) Source # | |
| (TypeError (('Text "Atom ForAll is not supported by ZipMatchFieldsFold" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType ('ForAll a)) :: Constraint) => ZipMatchFieldsFold ('ForAll a :: Atom d Type) Source # | |
| ZipMatchK k => ZipMatchFieldsFold ('Kon k :: Atom d Type) Source # | |
| ApplyMappings v => ZipMatchFieldsFold ('Var v :: Atom d Type) Source # | |
| (ZipMatchFieldsFold t1, ZipMatchFieldsFold t2, ZipMatchFoldK k) => ZipMatchFieldsFold ((('Kon k :: Atom d (Type -> Type -> Type)) ':@: t1) ':@: t2 :: Atom d Type) Source # | |
| (ZipMatchFieldsFold t, ZipMatchFoldK k) => ZipMatchFieldsFold (('Kon k :: Atom d (Type -> Type)) ':@: t :: Atom d Type) Source # | |
| (TypeError ((('Text "Atom :@: is not supported by ZipMatchFieldsFold is a general form:" ':$$: 'Text " when attempting to use a generic instance for") ':$$: 'ShowType (f ':@: t)) ':$$: (('ShowType f ':<>: 'Text " : ") ':<>: 'ShowType (Atom d (k1 -> Type)))) :: Constraint) => ZipMatchFieldsFold (f ':@: t :: Atom d Type) Source # | |
| (TypeError (((('Text "The type constructor is kind-polymorphic:" ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (kk -> Type))) ':$$: 'Text "Possible fix:") ':$$: 'Text " add an explicit kind signature") ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (Type -> Type))) :: Constraint) => ZipMatchFieldsFold (('Kon k :: Atom d (kk -> Type)) ':@: t :: Atom d Type) Source # | |
| (TypeError (((('Text "The type constructor is kind-polymorphic:" ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (kk1 -> kk2 -> Type))) ':$$: 'Text "Possible fix:") ':$$: 'Text " add an explicit kind signature") ':$$: ((('Text " " ':<>: 'ShowType k) ':<>: 'Text " : ") ':<>: 'ShowType (Type -> Type -> Type))) :: Constraint) => ZipMatchFieldsFold ((('Kon k :: Atom d (kk1 -> kk2 -> Type)) ':@: t1) ':@: t2 :: Atom d Type) Source # | |