@@ -38,6 +38,7 @@ import Data.Generics.Sum.Internal.Constructors
38import Data.Kind (Constraint, Type)
38import Data.Kind (Constraint, Type)
39import GHC.Generics (Generic (Rep))
39import GHC.Generics (Generic (Rep))
40import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
40import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
41+import Data.Type.Bool (If)
43-- >>> :set -XTypeApplications
44-- >>> :set -XTypeApplications
@@ -66,7 +67,7 @@ import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
68-- |Sums that have a constructor with a given name.
69-- |Sums that have a constructor with a given name.
69−class AsConstructor (ctor :: Symbol) a s | s ctor -> a where
70+class AsConstructor (ctor :: Symbol) s t a b | s ctor -> a where
70 -- |A prism that projects a named constructor from a sum. Compatible with the
71 -- |A prism that projects a named constructor from a sum. Compatible with the
71 -- lens package's 'Control.Lens.Prism' type.
72 -- lens package's 'Control.Lens.Prism' type.
@@ -81,18 +82,25 @@ class AsConstructor (ctor :: Symbol) a s | s ctor -> a where
82 -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal
83 -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal
83 -- Cat "Garfield" 6
84 -- Cat "Garfield" 6
84− _Ctor :: Prism' s a
85+ _Ctor :: Prism s t a b
87 ( Generic s
88 ( Generic s
88 , ErrorUnless ctor s (HasCtorP ctor (Rep s))
89 , ErrorUnless ctor s (HasCtorP ctor (Rep s))
93+ , GAsConstructor' ctor (Rep s) a
94+ , GAsConstructor' ctor (Rep s') a'
89− , GAsConstructor ctor (Rep s) a
95+ , GAsConstructor ctor (Rep s) (Rep t) a b
96+ , '(t', b') ~ If (IsParam a') '(Change s' (IndexOf a') b, P (IndexOf a') b) '(s', b)
90− ) => AsConstructor ctor a s where
98+ ) => AsConstructor ctor s t a b where
92 _Ctor = repIso . _GCtor @ctor
100 _Ctor = repIso . _GCtor @ctor
94-- See Note [Uncluttering type signatures]
102-- See Note [Uncluttering type signatures]
95−instance {-# OVERLAPPING #-} AsConstructor ctor Void Void where
103+instance {-# OVERLAPPING #-} AsConstructor ctor Void Void Void Void where
96 _Ctor = undefined
104 _Ctor = undefined
98type family ErrorUnless (ctor :: Symbol) (s :: Type) (contains :: Bool) :: Constraint where
106type family ErrorUnless (ctor :: Symbol) (s :: Type) (contains :: Bool) :: Constraint where