@@ -1,4 +1,5 @@
11{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE ConstraintKinds #-}
23{-# LANGUAGE DataKinds #-}
34{-# LANGUAGE FlexibleInstances #-}
45{-# LANGUAGE FunctionalDependencies #-}
@@ -25,39 +26,41 @@
2526
2627module Data.Generics.Sum.Internal.Constructors
2728 ( GAsConstructor (..)
29+ , GAsConstructor'
2830 ) where
2931
3032import Data.Generics.Internal.Families
3133import Data.Generics.Internal.HList
3234import Data.Generics.Internal.Lens
3335
34−import Data.Kind (Type)
3536import GHC.Generics
3637import GHC.TypeLits (Symbol)
3738
3839-- |As 'AsConstructor' but over generic representations as defined by
3940-- "GHC.Generics".
40−class GAsConstructor (ctor :: Symbol) (f :: Type -> Type) a | ctor f -> a where
41− _GCtor :: Prism' (f x) a
41+class GAsConstructor (ctor :: Symbol) s t a b | ctor s -> a, ctor t -> b where
42+ _GCtor :: Prism (s x) (t x) a b
43+
44+type GAsConstructor' ctor s a = GAsConstructor ctor s s a a
4245
4346instance
4447 ( GCollectible f as
4548 , ListTuple a as
46− ) => GAsConstructor ctor (M1 C ('MetaCons ctor fixity fields) f) a where
49+ ) => GAsConstructor ctor (M1 C ('MetaCons ctor fixity fields) f) (M1 C ('MetaCons ctor fixity fields) f) a a where
4750
4851 _GCtor = prism (M1 . gfromCollection . tupleToList) (Right . listToTuple @_ @as . gtoCollection . unM1)
4952
50−instance GSumAsConstructor ctor l r a (HasCtorP ctor l) => GAsConstructor ctor (l :+: r) a where
51− _GCtor = _GSumCtor @ctor @l @r @a @(HasCtorP ctor l)
53+instance GSumAsConstructor ctor (HasCtorP ctor l) l r l' r' a b => GAsConstructor ctor (l :+: r) (l' :+: r') a b where
54+ _GCtor = _GSumCtor @ctor @(HasCtorP ctor l)
5255
53−instance GAsConstructor ctor f a => GAsConstructor ctor (M1 D meta f) a where
56+instance GAsConstructor ctor f f' a b => GAsConstructor ctor (M1 D meta f) (M1 D meta f') a b where
5457 _GCtor = mIso . _GCtor @ctor
5558
56−class GSumAsConstructor (ctor :: Symbol) l r a (contains :: Bool) | ctor l r contains -> a where
57− _GSumCtor :: Prism' ((l :+: r) x) a
59+class GSumAsConstructor (ctor :: Symbol) (contains :: Bool) l r l' r' a b | ctor l r -> a, ctor l' r' -> b where
60+ _GSumCtor :: Prism ((l :+: r) x) ((l' :+: r') x) a b
5861
59−instance GAsConstructor ctor l a => GSumAsConstructor ctor l r a 'True where
62+instance GAsConstructor ctor l l' a b => GSumAsConstructor ctor 'True l r l' r a b where
6063 _GSumCtor = left . _GCtor @ctor
6164
62−instance GAsConstructor ctor r a => GSumAsConstructor ctor l r a 'False where
65+instance GAsConstructor ctor r r' a b => GSumAsConstructor ctor 'False l r l r' a b where
6366 _GSumCtor = right . _GCtor @ctor