@@ -46,33 +46,36 @@ import Data.Type.Bool (If)
46-- >>> :set -XDeriveGeneric
46-- >>> :set -XDeriveGeneric
47-- >>> import GHC.Generics
47-- >>> import GHC.Generics
48-- >>> :m +Data.Generics.Internal.Lens
48-- >>> :m +Data.Generics.Internal.Lens
49+-- >>> :m +Data.Generics.Product.Fields
50+-- >>> :m +Data.Function
50−-- data Animal
52+-- data Animal a
51−-- = Dog Dog
53+-- = Dog (Dog a)
52-- | Cat Name Age
54-- | Cat Name Age
53-- | Duck Age
55-- | Duck Age
54-- deriving (Generic, Show)
56-- deriving (Generic, Show)
55−-- data Dog
57+-- data Dog a
57−-- { name :: Name
59+-- { name :: Name
58−-- , age :: Age
60+-- , age :: Age
60-- deriving (Generic, Show)
63-- deriving (Generic, Show)
61-- type Name = String
64-- type Name = String
62-- type Age = Int
65-- type Age = Int
63−-- dog, cat, duck :: Animal
66+-- dog, cat, duck :: Animal Int
64−-- dog = Dog (MkDog "Shep" 3)
67+-- dog = Dog (MkDog "Shep" 3 30)
65-- cat = Cat "Mog" 5
68-- cat = Cat "Mog" 5
66-- duck = Duck 2
69-- duck = Duck 2
69-- |Sums that have a constructor with a given name.
72-- |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
71 -- |A prism that projects a named constructor from a sum. Compatible with the
74 -- |A prism that projects a named constructor from a sum. Compatible with the
72 -- lens package's 'Control.Lens.Prism' type.
75 -- lens package's 'Control.Lens.Prism' type.
74 -- >>> dog ^? _Ctor @"Dog"
77 -- >>> dog ^? _Ctor @"Dog"
75− -- Just (MkDog {name = "Shep", age = 3})
78+ -- Just (MkDog {name = "Shep", age = 3, fieldA = 30})
77 -- >>> dog ^? _Ctor @"Cat"
80 -- >>> dog ^? _Ctor @"Cat"
78 -- Nothing
81 -- Nothing
@@ -80,7 +83,7 @@ class AsConstructor (ctor :: Symbol) s t a b | s ctor -> a where
80 -- >>> cat ^? _Ctor @"Cat"
83 -- >>> cat ^? _Ctor @"Cat"
81 -- Just ("Mog",5)
84 -- Just ("Mog",5)
83− -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal
86+ -- >>> _Ctor @"Cat" # ("Garfield", 6) :: Animal Int
84 -- Cat "Garfield" 6
87 -- Cat "Garfield" 6
85 _Ctor :: Prism s t a b
88 _Ctor :: Prism s t a b
@@ -93,14 +96,16 @@ instance
93 , GAsConstructor' ctor (Rep s) a
96 , GAsConstructor' ctor (Rep s) a
94 , GAsConstructor' ctor (Rep s') a'
97 , GAsConstructor' ctor (Rep s') a'
95 , GAsConstructor ctor (Rep s) (Rep t) a b
98 , 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)
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
97− , t ~ UnProxied t'
102+ , t ~ Generalise (UnProxied t') p
98 ) => AsConstructor ctor s t a b where
103 ) => AsConstructor ctor s t a b where
100 _Ctor = repIso . _GCtor @ctor
105 _Ctor = repIso . _GCtor @ctor
102-- See Note [Uncluttering type signatures]
107-- 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
104 _Ctor = undefined
109 _Ctor = undefined
106type family ErrorUnless (ctor :: Symbol) (s :: Type) (contains :: Bool) :: Constraint where
111type family ErrorUnless (ctor :: Symbol) (s :: Type) (contains :: Bool) :: Constraint where