@@ -46,33 +46,36 @@ import Data.Type.Bool (If)
4646-- >>> :set -XDeriveGeneric
4747-- >>> import GHC.Generics
4848-- >>> :m +Data.Generics.Internal.Lens
49+-- >>> :m +Data.Generics.Product.Fields
50+-- >>> :m +Data.Function
4951-- >>> :{
50−-- data Animal
51−-- = Dog Dog
52+-- data Animal a
53+-- = Dog (Dog a)
5254-- | Cat Name Age
5355-- | Duck Age
5456-- deriving (Generic, Show)
55−-- data Dog
57+-- data Dog a
5658-- = MkDog
57−-- { name :: Name
58−-- , age :: Age
59+-- { name :: Name
60+-- , age :: Age
61+-- , fieldA :: a
5962-- }
6063-- deriving (Generic, Show)
6164-- type Name = String
6265-- type Age = Int
63−-- dog, cat, duck :: Animal
64−-- dog = Dog (MkDog "Shep" 3)
66+-- dog, cat, duck :: Animal Int
67+-- dog = Dog (MkDog "Shep" 3 30)
6568-- cat = Cat "Mog" 5
6669-- duck = Duck 2
6770-- :}
6871
6972-- |Sums that have a constructor with a given name.
70−class AsConstructor (ctor :: Symbol) s t a b | s ctor -> a where
73+class AsConstructor (ctor :: Symbol) s t a b | ctor s -> a, ctor t -> b where
7174 -- |A prism that projects a named constructor from a sum. Compatible with the
7275 -- lens package's 'Control.Lens.Prism' type.
7376 --
7477 -- >>> dog ^? _Ctor @"Dog"
75− -- Just (MkDog {name = "Shep", age = 3})
78+ -- Just (MkDog {name = "Shep", age = 3, fieldA = 30})
7679 --
7780 -- >>> dog ^? _Ctor @"Cat"
7881 -- Nothing
@@ -80,7 +83,7 @@ class AsConstructor (ctor :: Symbol) s t a b | s ctor -> a where
8083 -- >>> cat ^? _Ctor @"Cat"
8184 -- Just ("Mog",5)
8285 --
83− -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal
86+ -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal Int
8487 -- Cat "Garfield" 6
8588 _Ctor :: Prism s t a b
8689
@@ -93,14 +96,16 @@ instance
9396 , GAsConstructor' ctor (Rep s) a
9497 , GAsConstructor' ctor (Rep s') a'
9598 , 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)
97− , t ~ UnProxied t'
99+ , aa ~ PSub (Unify a' a)
100+ , '(t', b') ~ IfEq a a' '(s', a') (If (IsSingleton aa) '(Change s' (Fst (Head aa)) Skolem, Change a' (Fst (Head aa)) Skolem) '(s', a'))
101+ , b ~ Generalise (UnProxied b') p
102+ , t ~ Generalise (UnProxied t') p
98103 ) => AsConstructor ctor s t a b where
99104
100105 _Ctor = repIso . _GCtor @ctor
101106
102107-- See Note [Uncluttering type signatures]
103−instance {-# OVERLAPPING #-} AsConstructor ctor Void Void Void Void where
108+instance {-# OVERLAPPING #-} AsConstructor ctor (Void1 a) (Void1 b) a b where
104109 _Ctor = undefined
105110
106111type family ErrorUnless (ctor :: Symbol) (s :: Type) (contains :: Bool) :: Constraint where