on master help sign in
Drop (now redundant) meta elements from List and rename to HList
commitdb4a8102ac27cdf52a6bcfdbf7b82f77630383b1 authorCsongor Kiss <csongor.kiss@habito.com> dateWed 8 Aug 2018, 14:17 (8 years ago) parent136c68f
36 files changed+428−480
LICENSE+1−1 generic-lens.cabal+2−2 src/Data/Generics/Internal/Families.hs+1−1 src/Data/Generics/Internal/Families/Collect.hs+2−2 src/Data/Generics/Internal/Families/Has.hs+4−4 src/Data/Generics/Internal/Profunctor/Iso.hs+1−1 src/Data/Generics/Internal/Profunctor/Lens.hs+1−1 src/Data/Generics/Internal/Profunctor/Prism.hs+1−1 src/Data/Generics/Internal/VL/Iso.hs+1−1 src/Data/Generics/Internal/VL/Lens.hs+1−1 src/Data/Generics/Internal/VL/Prism.hs+1−1 src/Data/Generics/Internal/VL/Traversal.hs+1−1 src/Data/Generics/Labels.hs+1−1 src/Data/Generics/Product.hs+3−3 src/Data/Generics/Product/Any.hs+1−1 src/Data/Generics/Product/Fields.hs+1−1 src/Data/Generics/Product/HList.hs+45 src/Data/Generics/Product/Internal/Constraints.hs+2−7 src/Data/Generics/Product/Internal/GLens.hs+1−1 src/Data/Generics/Product/Internal/HList.hs+324 src/Data/Generics/Product/Internal/List.hs−337 src/Data/Generics/Product/Internal/Positions.hs+1−1 src/Data/Generics/Product/Internal/Subtype.hs+1−1 src/Data/Generics/Product/List.hs−78 src/Data/Generics/Product/Positions.hs+1−1 src/Data/Generics/Product/Subtype.hs+1−1 src/Data/Generics/Product/Typed.hs+1−1 src/Data/Generics/Product/Types.hs+1−1 src/Data/Generics/Sum.hs+1−1 src/Data/Generics/Sum/Any.hs+1−1 src/Data/Generics/Sum/Constructors.hs+1−1 src/Data/Generics/Sum/Internal/Constructors.hs+5−6 src/Data/Generics/Sum/Internal/Subtype.hs+8−8 src/Data/Generics/Sum/Internal/Typed.hs+8−8 src/Data/Generics/Sum/Subtype.hs+1−1 src/Data/Generics/Sum/Typed.hs+2−2
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2017, Csongor Kiss
1+Copyright (c) 2018, Csongor Kiss
22
33All rights reserved.
44
generic-lens.cabal+2−2
@@ -32,7 +32,7 @@ library
3232 , Data.Generics.Product.Typed
3333 , Data.Generics.Product.Types
3434 , Data.Generics.Product.Constraints
35− , Data.Generics.Product.List
35+ , Data.Generics.Product.HList
3636 , Data.Generics.Internal.GenericN
3737
3838 , Data.Generics.Sum
@@ -63,7 +63,7 @@ library
6363 , Data.Generics.Product.Internal.Subtype
6464
6565 , Data.Generics.Product.Internal.Constraints
66− , Data.Generics.Product.Internal.List
66+ , Data.Generics.Product.Internal.HList
6767
6868 build-depends: base >= 4.9 && <= 5.0
6969 , profunctors >= 5.0 && <= 6.0
src/Data/Generics/Internal/Families.hs+1−1
@@ -9,7 +9,7 @@
99-----------------------------------------------------------------------------
1010-- |
1111-- Module : Data.Generics.Internal.Families
12−-- Copyright : (C) 2017 Csongor Kiss
12+-- Copyright : (C) 2018 Csongor Kiss
1313-- License : BSD3
1414-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1515-- Stability : experimental
src/Data/Generics/Internal/Families/Collect.hs+2−2
@@ -7,7 +7,7 @@
77-----------------------------------------------------------------------------
88-- |
99-- Module : Data.Generics.Internal.Families.Collect
10−-- Copyright : (C) 2017 Csongor Kiss
10+-- Copyright : (C) 2018 Csongor Kiss
1111-- License : BSD3
1212-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1313-- Stability : experimental
@@ -28,7 +28,7 @@ import Data.Type.Equality (type (==))
2828import GHC.Generics
2929import GHC.TypeLits (Symbol, CmpSymbol)
3030
31−import Data.Generics.Product.Internal.List (type (++))
31+import Data.Generics.Product.Internal.HList (type (++))
3232import Data.Generics.Internal.Families.Has (GTypes)
3333
3434data TypeStat
src/Data/Generics/Internal/Families/Has.hs+4−4
@@ -7,7 +7,7 @@
77-----------------------------------------------------------------------------
88-- |
99-- Module : Data.Generics.Internal.Families.Has
10−-- Copyright : (C) 2017 Csongor Kiss
10+-- Copyright : (C) 2018 Csongor Kiss
1111-- License : BSD3
1212-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1313-- Stability : experimental
@@ -30,7 +30,7 @@ import GHC.Generics
3030import GHC.TypeLits (Symbol, Nat)
3131import Data.Kind (Type)
3232
33−import Data.Generics.Product.Internal.List
33+import Data.Generics.Product.Internal.HList
3434
3535-- Note: these could be factored out into a single traversal
3636
@@ -116,11 +116,11 @@ type family HasCtorP (ctor :: Symbol) f :: Bool where
116116 HasCtorP ctor _
117117 = 'False
118118
119−type family GTypes (rep :: Type -> Type) :: [((), Type)] where
119+type family GTypes (rep :: Type -> Type) :: [(Type)] where
120120 GTypes (l :*: r)
121121 = GTypes l ++ GTypes r
122122 GTypes (K1 _ a)
123− = '[ '( '(), a)]
123+ = '[ a]
124124 GTypes (M1 _ m a)
125125 = GTypes a
126126 GTypes U1 = '[]
src/Data/Generics/Internal/Profunctor/Iso.hs+1−1
@@ -9,7 +9,7 @@
99-----------------------------------------------------------------------------
1010-- |
1111-- Module : Data.Generics.Internal.Profunctor.Iso
12−-- Copyright : (C) 2017 Csongor Kiss
12+-- Copyright : (C) 2018 Csongor Kiss
1313-- License : BSD3
1414-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1515-- Stability : experimental
src/Data/Generics/Internal/Profunctor/Lens.hs+1−1
@@ -10,7 +10,7 @@
1010-----------------------------------------------------------------------------
1111-- |
1212-- Module : Data.Generics.Internal.Profunctor.Lens
13−-- Copyright : (C) 2017 Csongor Kiss
13+-- Copyright : (C) 2018 Csongor Kiss
1414-- License : BSD3
1515-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1616-- Stability : experimental
src/Data/Generics/Internal/Profunctor/Prism.hs+1−1
@@ -10,7 +10,7 @@
1010-----------------------------------------------------------------------------
1111-- |
1212-- Module : Data.Generics.Internal.Profunctor.Prism
13−-- Copyright : (C) 2017 Csongor Kiss
13+-- Copyright : (C) 2018 Csongor Kiss
1414-- License : BSD3
1515-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1616-- Stability : experimental
src/Data/Generics/Internal/VL/Iso.hs+1−1
@@ -9,7 +9,7 @@
99-----------------------------------------------------------------------------
1010-- |
1111-- Module : Data.Generics.Internal.VL.Iso
12−-- Copyright : (C) 2017 Csongor Kiss
12+-- Copyright : (C) 2018 Csongor Kiss
1313-- License : BSD3
1414-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1515-- Stability : experimental
src/Data/Generics/Internal/VL/Lens.hs+1−1
@@ -10,7 +10,7 @@
1010-----------------------------------------------------------------------------
1111-- |
1212-- Module : Data.Generics.Internal.VL.Lens
13−-- Copyright : (C) 2017 Csongor Kiss
13+-- Copyright : (C) 2018 Csongor Kiss
1414-- License : BSD3
1515-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1616-- Stability : experimental
src/Data/Generics/Internal/VL/Prism.hs+1−1
@@ -9,7 +9,7 @@
99-----------------------------------------------------------------------------
1010-- |
1111-- Module : Data.Generics.Internal.VL.Prism
12−-- Copyright : (C) 2017 Csongor Kiss
12+-- Copyright : (C) 2018 Csongor Kiss
1313-- License : BSD3
1414-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1515-- Stability : experimental
src/Data/Generics/Internal/VL/Traversal.hs+1−1
@@ -11,7 +11,7 @@
1111-----------------------------------------------------------------------------
1212-- |
1313-- Module : Data.Generics.Internal.VL.Traversal
14−-- Copyright : (C) 2017 Csongor Kiss
14+-- Copyright : (C) 2018 Csongor Kiss
1515-- License : BSD3
1616-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1717-- Stability : experimental
src/Data/Generics/Labels.hs+1−1
@@ -11,7 +11,7 @@
1111--------------------------------------------------------------------------------
1212-- |
1313-- Module : Data.Generics.Labels
14−-- Copyright : (C) 2017 Csongor Kiss
14+-- Copyright : (C) 2018 Csongor Kiss
1515-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1616-- License : BSD3
1717-- Stability : experimental
src/Data/Generics/Product.hs+3−3
@@ -1,7 +1,7 @@
11-----------------------------------------------------------------------------
22-- |
33-- Module : Data.Generics.Product
4−-- Copyright : (C) 2017 Csongor Kiss
4+-- Copyright : (C) 2018 Csongor Kiss
55-- License : BSD3
66-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
77-- Stability : experimental
@@ -22,7 +22,7 @@ module Data.Generics.Product
2222 , module Data.Generics.Product.Positions
2323 , module Data.Generics.Product.Subtype
2424 , module Data.Generics.Product.Typed
25− , module Data.Generics.Product.List
25+ , module Data.Generics.Product.HList
2626 -- *Traversals
2727 , module Data.Generics.Product.Types
2828 , module Data.Generics.Product.Param
@@ -37,4 +37,4 @@ import Data.Generics.Product.Typed
3737import Data.Generics.Product.Types
3838import Data.Generics.Product.Constraints
3939import Data.Generics.Product.Param
40−import Data.Generics.Product.List
40+import Data.Generics.Product.HList
src/Data/Generics/Product/Any.hs+1−1
@@ -12,7 +12,7 @@
1212-----------------------------------------------------------------------------
1313-- |
1414-- Module : Data.Generics.Product.Any
15−-- Copyright : (C) 2017 Csongor Kiss
15+-- Copyright : (C) 2018 Csongor Kiss
1616-- License : BSD3
1717-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1818-- Stability : experimental
src/Data/Generics/Product/Fields.hs+1−1
@@ -16,7 +16,7 @@
1616-----------------------------------------------------------------------------
1717-- |
1818-- Module : Data.Generics.Product.Fields
19−-- Copyright : (C) 2017 Csongor Kiss
19+-- Copyright : (C) 2018 Csongor Kiss
2020-- License : BSD3
2121-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2222-- Stability : experimental
src/Data/Generics/Product/HList.hsnew file+45
@@ -0,0 +1,45 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE FunctionalDependencies #-}
5+{-# LANGUAGE MonoLocalBinds #-}
6+{-# LANGUAGE ScopedTypeVariables #-}
7+{-# LANGUAGE TypeInType #-}
8+{-# LANGUAGE UndecidableInstances #-}
9+
10+-----------------------------------------------------------------------------
11+-- |
12+-- Module : Data.Generics.Product.HList
13+-- Copyright : (C) 2018 Csongor Kiss
14+-- License : BSD3
15+-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
16+-- Stability : experimental
17+-- Portability : non-portable
18+--
19+-- Derive an isomorphism between a product type and a flat HList.
20+--
21+-----------------------------------------------------------------------------
22+
23+module Data.Generics.Product.HList
24+ ( IsList (..)
25+ ) where
26+
27+import Data.Generics.Product.Internal.HList
28+import Data.Kind
29+import GHC.Generics
30+import Data.Generics.Internal.Profunctor.Iso
31+
32+class IsList
33+ (f :: Type)
34+ (g :: Type)
35+ (as :: [Type])
36+ (bs :: [Type]) | f -> as, g -> bs where
37+ list :: Iso f g (HList as) (HList bs)
38+
39+instance
40+ ( Generic f
41+ , Generic g
42+ , GIsList (Rep f) (Rep g) as bs
43+ ) => IsList f g as bs where
44+ list = repIso . glist
45+ {-# INLINE list #-}
src/Data/Generics/Product/Internal/Constraints.hs+2−7
@@ -15,7 +15,7 @@
1515-----------------------------------------------------------------------------
1616-- |
1717-- Module : Data.Generics.Product.Internal.Constraints
18−-- Copyright : (C) 2017 Csongor Kiss
18+-- Copyright : (C) 2018 Csongor Kiss
1919-- License : BSD3
2020-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2121-- Stability : experimental
@@ -31,13 +31,13 @@ module Data.Generics.Product.Internal.Constraints
3131 (
3232 GHasConstraints (..)
3333 , GHasConstraints' (..)
34− , HList (..)
3534 ) where
3635
3736import Data.Kind (Type, Constraint)
3837import GHC.Generics
3938import Data.Generics.Internal.VL.Iso
4039import Data.Generics.Internal.VL.Traversal
40+import Data.Generics.Product.Internal.HList
4141
4242-- | Constrained traversal.
4343class GHasConstraints' (c :: * -> Constraint) (f :: * -> *) where
@@ -117,11 +117,6 @@ gtypes hl s = gconstraints @(Contains as) (pick hl) s
117117
118118--------------------------------------------------------------------------------
119119
120−data HList (ts :: [Type]) where
121− HNil :: HList '[]
122− (:>) :: a -> HList as -> HList (a ': as)
123−infixr 5 :>
124−
125120-- >>> :kind! Functions '[Int, Char, Bool] Maybe
126121-- '[Int -> Maybe Int, Char -> Maybe Char, Bool -> Maybe Bool]
127122type family Functions (ts :: [Type]) (g :: Type -> Type) = r | r -> ts where
src/Data/Generics/Product/Internal/GLens.hs+1−1
@@ -17,7 +17,7 @@
1717-----------------------------------------------------------------------------
1818-- |
1919-- Module : Data.Generics.Product.Internal.GLens
20−-- Copyright : (C) 2017 Csongor Kiss
20+-- Copyright : (C) 2018 Csongor Kiss
2121-- License : BSD3
2222-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2323-- Stability : experimental
src/Data/Generics/Product/Internal/HList.hsnew file+324
@@ -0,0 +1,324 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE CPP #-}
3+{-# LANGUAGE ConstraintKinds #-}
4+{-# LANGUAGE FlexibleInstances #-}
5+{-# LANGUAGE FunctionalDependencies #-}
6+{-# LANGUAGE GADTs #-}
7+{-# LANGUAGE ScopedTypeVariables #-}
8+{-# LANGUAGE TupleSections #-}
9+{-# LANGUAGE TypeApplications #-}
10+{-# LANGUAGE TypeFamilies #-}
11+{-# LANGUAGE TypeInType #-}
12+{-# LANGUAGE TypeOperators #-}
13+{-# LANGUAGE UndecidableInstances #-}
14+
15+#if __GLASGOW_HASKELL__ == 802
16+{-# OPTIONS_GHC -fno-solve-constant-dicts #-}
17+#endif
18+
19+
20+-----------------------------------------------------------------------------
21+-- |
22+-- Module : Data.Generics.Product.Internal.HList
23+-- Copyright : (C) 2018 Csongor Kiss
24+-- License : BSD3
25+-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
26+-- Stability : experimental
27+-- Portability : non-portable
28+--
29+-- Derive an isomorphism between a product type and a flat HList.
30+--
31+-----------------------------------------------------------------------------
32+
33+module Data.Generics.Product.Internal.HList
34+ ( GIsList(..)
35+ , IndexList (..)
36+ , HList (..)
37+ , type (++)
38+ , Elem
39+ , ListTuple (..)
40+ , TupleToList
41+ ) where
42+
43+#if __GLASGOW_HASKELL__ < 804
44+import Data.Semigroup
45+#endif
46+import GHC.TypeLits
47+
48+import Data.Kind (Type)
49+import GHC.Generics
50+import Data.Profunctor
51+import Data.Generics.Internal.Profunctor.Lens
52+import Data.Generics.Internal.Profunctor.Iso
53+
54+data HList (as :: [Type]) where
55+ Nil :: HList '[]
56+ (:>) :: a -> HList as -> HList (a ': as)
57+
58+infixr 5 :>
59+
60+type family ((as :: [k]) ++ (bs :: [k])) :: [k] where
61+ '[] ++ bs = bs
62+ (a ': as) ++ bs = a ': as ++ bs
63+
64+instance Semigroup (HList '[]) where
65+ _ <> _ = Nil
66+
67+instance Monoid (HList '[]) where
68+ mempty = Nil
69+ mappend _ _ = Nil
70+
71+instance (Semigroup a, Semigroup (HList as)) => Semigroup (HList (a ': as)) where
72+ (x :> xs) <> (y :> ys) = (x <> y) :> (xs <> ys)
73+
74+instance (Monoid a, Monoid (HList as)) => Monoid (HList (a ': as)) where
75+ mempty = mempty :> mempty
76+ mappend (x :> xs) (y :> ys) = mappend x y :> mappend xs ys
77+
78+class Elem (as :: [(k, Type)]) (key :: k) (i :: Nat) a | as key -> i a
79+instance {-# OVERLAPPING #-} pos ~ 0 => Elem (a ': xs) key pos a
80+instance (Elem xs key i a, pos ~ (i + 1)) => Elem (x ': xs) key pos a
81+
82+class GIsList
83+ (f :: Type -> Type)
84+ (g :: Type -> Type)
85+ (as :: [Type])
86+ (bs :: [Type]) | f -> as, g -> bs, bs f -> g, as g -> f where
87+
88+ glist :: Iso (f x) (g x) (HList as) (HList bs)
89+
90+ -- We define this reversed version, otherwise uses of `fromIso glist` are not
91+ -- properly inlined by GHC 8.0.2.
92+ -- This is not actually used.
93+ glistR :: Iso (HList bs) (HList as) (g x) (f x)
94+ glistR = fromIso glist
95+
96+instance
97+ ( GIsList l l' as as'
98+ , GIsList r r' bs bs'
99+ , Appending HList as bs cs as' bs' cs'
100+ , cs ~ (as ++ bs)
101+ , cs' ~ (as' ++ bs')
102+ ) => GIsList (l :*: r) (l' :*: r') cs cs' where
103+
104+ glist = prodIso . pairing glist glist . appending
105+ {-# INLINE glist #-}
106+
107+instance GIsList f g as bs => GIsList (M1 t meta f) (M1 t meta g) as bs where
108+ glist = mIso . glist
109+ {-# INLINE glist #-}
110+
111+instance GIsList (Rec0 a) (Rec0 b) '[a] '[b] where
112+ glist = kIso . singleton
113+ {-# INLINE glist #-}
114+
115+instance GIsList U1 U1 '[] '[] where
116+ glist = iso (const Nil) (const U1)
117+ {-# INLINE glist #-}
118+
119+--------------------------------------------------------------------------------
120+-- | as ++ bs === cs
121+class Appending f (as :: [k]) bs cs (as' :: [k]) bs' cs' | as bs cs cs' -> as' bs', as' bs' cs cs' -> as bs, as bs -> cs, as' bs' -> cs' where
122+ appending :: Iso (f as, f bs) (f as', f bs') (f cs) (f cs')
123+
124+-- | [] ++ bs === bs
125+instance Appending HList '[] bs bs '[] bs' bs' where
126+ appending = iso (\(_, b) -> b) (Nil,)
127+
128+-- | (a : as) ++ bs === (a : cs)
129+instance
130+ Appending HList as bs cs as' bs' cs' -- as ++ bs == cs
131+ => Appending HList (a ': as) bs (a ': cs) (a' ': as') bs' (a' ': cs') where
132+ appending
133+ = pairing (fromIso consing) id -- ((a, as), bs)
134+ . assoc3 -- (a, (as, bs))
135+ . pairing id appending -- (a, cs)
136+ . consing -- (a : cs)
137+
138+singleton :: Iso a b (HList '[ a]) (HList '[ b])
139+singleton = iso (:> Nil) (\(x :> _) -> x)
140+
141+consing :: Iso (a, HList as) (b, HList bs) (HList (a ': as)) (HList (b ': bs))
142+consing = iso (\(x, xs) -> x :> xs) (\(x :> xs) -> (x, xs))
143+
144+--------------------------------------------------------------------------------
145+class IndexList (i :: Nat) as bs a b | i as -> a, i bs -> b, i as b -> bs, i bs a -> as where
146+ point :: Lens (HList as) (HList bs) a b
147+
148+instance {-# OVERLAPPING #-}
149+ ( as ~ (a ': as')
150+ , bs ~ (b ': as')
151+ ) => IndexList 0 as bs a b where
152+ point = lens (\(x :> xs) -> (xs, x)) (\(xs, x') -> x' :> xs)
153+ {-# INLINE point #-}
154+
155+instance
156+ ( IndexList (n - 1) as' bs' a b
157+ , as ~ (x ': as')
158+ , bs ~ (x ': bs')
159+ ) => IndexList n as bs a b where
160+ point = fromIso consing . alongside id (point @(n-1)) . second'
161+ {-# INLINE point #-}
162+
163+--------------------------------------------------------------------------------
164+-- * Convert tuples to/from HLists
165+
166+class ListTuple (tuple :: Type) (as :: [Type]) | as -> tuple where
167+ type ListToTuple as :: Type
168+ tupled :: Iso' (HList as) tuple
169+ tupled = iso listToTuple tupleToList
170+
171+ tupleToList :: tuple -> HList as
172+ listToTuple :: HList as -> tuple
173+
174+instance ListTuple () '[] where
175+ type ListToTuple '[] = ()
176+ tupleToList _ = Nil
177+ listToTuple _ = ()
178+
179+instance ListTuple a '[ a] where
180+ type ListToTuple '[ a] = a
181+ tupleToList a
182+ = a :> Nil
183+ listToTuple (a :> Nil)
184+ = a
185+
186+instance ListTuple (a, b) '[ a, b] where
187+ type ListToTuple '[ a, b] = (a, b)
188+ tupleToList (a, b)
189+ = a :> b :> Nil
190+ listToTuple (a :> b :> Nil)
191+ = (a, b)
192+
193+instance ListTuple (a, b, c) '[ a, b, c] where
194+ type ListToTuple '[ a, b, c] = (a, b, c)
195+ tupleToList (a, b, c)
196+ = a :> b :> c :> Nil
197+ listToTuple (a :> b :> c :> Nil)
198+ = (a, b, c)
199+
200+instance ListTuple (a, b, c, d) '[ a, b, c, d] where
201+ type ListToTuple '[ a, b, c, d] = (a, b, c, d)
202+ tupleToList (a, b, c, d)
203+ = a :> b :> c :> d:> Nil
204+ listToTuple (a :> b :> c :> d :> Nil)
205+ = (a, b, c, d)
206+
207+instance ListTuple (a, b, c, d, e) '[ a, b, c, d, e] where
208+ type ListToTuple '[ a, b, c, d, e] = (a, b, c, d, e)
209+ tupleToList (a, b, c, d, e)
210+ = a :> b :> c :> d:> e :> Nil
211+ listToTuple (a :> b :> c :> d :> e :> Nil)
212+ = (a, b, c, d, e)
213+
214+instance ListTuple (a, b, c, d, e, f) '[ a, b, c, d, e, f] where
215+ type ListToTuple '[ a, b, c, d, e, f] = (a, b, c, d, e, f)
216+ tupleToList (a, b, c, d, e, f)
217+ = a :> b :> c :> d:> e :> f :> Nil
218+ listToTuple (a :> b :> c :> d :> e :> f :> Nil)
219+ = (a, b, c, d, e, f)
220+
221+instance ListTuple (a, b, c, d, e, f, g) '[ a, b, c, d, e, f, g] where
222+ type ListToTuple '[ a, b, c, d, e, f, g] = (a, b, c, d, e, f, g)
223+ tupleToList (a, b, c, d, e, f, g)
224+ = a :> b :> c :> d:> e :> f :> g :> Nil
225+ listToTuple (a :> b :> c :> d :> e :> f :> g :> Nil)
226+ = (a, b, c, d, e, f, g)
227+
228+instance ListTuple (a, b, c, d, e, f, g, h) '[ a, b, c, d, e, f, g, h] where
229+ type ListToTuple '[ a, b, c, d, e, f, g, h] = (a, b, c, d, e, f, g, h)
230+ tupleToList (a, b, c, d, e, f, g, h)
231+ = a :> b :> c :> d:> e :> f :> g :> h :> Nil
232+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> Nil)
233+ = (a, b, c, d, e, f, g, h)
234+
235+instance ListTuple (a, b, c, d, e, f, g, h, j) '[ a, b, c, d, e, f, g, h, j] where
236+ type ListToTuple '[ a, b, c, d, e, f, g, h, j] = (a, b, c, d, e, f, g, h, j)
237+ tupleToList (a, b, c, d, e, f, g, h, j)
238+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> Nil
239+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> Nil)
240+ = (a, b, c, d, e, f, g, h, j)
241+
242+instance ListTuple (a, b, c, d, e, f, g, h, j, k) '[ a, b, c, d, e, f, g, h, j, k] where
243+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k] = (a, b, c, d, e, f, g, h, j, k)
244+ tupleToList (a, b, c, d, e, f, g, h, j, k)
245+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> Nil
246+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> Nil)
247+ = (a, b, c, d, e, f, g, h, j, k)
248+
249+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l) '[ a, b, c, d, e, f, g, h, j, k, l] where
250+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l] = (a, b, c, d, e, f, g, h, j, k, l)
251+ tupleToList (a, b, c, d, e, f, g, h, j, k, l)
252+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> Nil
253+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> Nil)
254+ = (a, b, c, d, e, f, g, h, j, k, l)
255+
256+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m) '[ a, b, c, d, e, f, g, h, j, k, l, m] where
257+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m] = (a, b, c, d, e, f, g, h, j, k, l, m)
258+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m)
259+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> Nil
260+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> Nil)
261+ = (a, b, c, d, e, f, g, h, j, k, l, m)
262+
263+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n) '[ a, b, c, d, e, f, g, h, j, k, l, m, n] where
264+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n] = (a, b, c, d, e, f, g, h, j, k, l, m, n)
265+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n)
266+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> Nil
267+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> Nil)
268+ = (a, b, c, d, e, f, g, h, j, k, l, m, n)
269+
270+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o) '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o] where
271+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
272+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
273+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> Nil
274+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> Nil)
275+ = (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
276+
277+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p) '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p] where
278+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
279+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
280+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> Nil
281+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> Nil)
282+ = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
283+
284+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q) '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q] where
285+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
286+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
287+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> Nil
288+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> Nil)
289+ = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
290+
291+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r) '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r] where
292+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
293+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
294+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> Nil
295+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> Nil)
296+ = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
297+
298+instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s) '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s] where
299+ type ListToTuple '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
300+ tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
301+ = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> s :> Nil
302+ listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> s :> Nil)
303+ = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
304+
305+type family TupleToList a where
306+ TupleToList () = '[]
307+ TupleToList (a, b) = '[ a, b]
308+ TupleToList (a, b, c) = '[ a, b, c]
309+ TupleToList (a, b, c, d) = '[ a, b, c, d]
310+ TupleToList (a, b, c, d, e) = '[ a, b, c, d, e]
311+ TupleToList (a, b, c, d, e, f) = '[ a, b, c, d, e, f]
312+ TupleToList (a, b, c, d, e, f, g) = '[ a, b, c, d, e, f, g]
313+ TupleToList (a, b, c, d, e, f, g, h) = '[ a, b, c, d, e, f, g, h]
314+ TupleToList (a, b, c, d, e, f, g, h, j) = '[ a, b, c, d, e, f, g, h, j]
315+ TupleToList (a, b, c, d, e, f, g, h, j, k) = '[ a, b, c, d, e, f, g, h, j, k]
316+ TupleToList (a, b, c, d, e, f, g, h, j, k, l) = '[ a, b, c, d, e, f, g, h, j, k, l]
317+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m) = '[ a, b, c, d, e, f, g, h, j, k, l, m]
318+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n]
319+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o]
320+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p]
321+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q]
322+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r]
323+ TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s) = '[ a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s]
324+ TupleToList a = '[ a]
src/Data/Generics/Product/Internal/List.hsdeleted−337
@@ -1,337 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE CPP #-}
3−{-# LANGUAGE ConstraintKinds #-}
4−{-# LANGUAGE FlexibleInstances #-}
5−{-# LANGUAGE FunctionalDependencies #-}
6−{-# LANGUAGE GADTs #-}
7−{-# LANGUAGE ScopedTypeVariables #-}
8−{-# LANGUAGE TupleSections #-}
9−{-# LANGUAGE TypeApplications #-}
10−{-# LANGUAGE TypeFamilies #-}
11−{-# LANGUAGE TypeInType #-}
12−{-# LANGUAGE TypeOperators #-}
13−{-# LANGUAGE UndecidableInstances #-}
14−
15−#if __GLASGOW_HASKELL__ == 802
16−{-# OPTIONS_GHC -fno-solve-constant-dicts #-}
17−#endif
18−
19−
20−-----------------------------------------------------------------------------
21−-- |
22−-- Module : Data.Generics.Product.Internal.List
23−-- Copyright : (C) 2017 Csongor Kiss
24−-- License : BSD3
25−-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
26−-- Stability : experimental
27−-- Portability : non-portable
28−--
29−-- Derive an isomorphism between a product type and a flat HList.
30−--
31−-----------------------------------------------------------------------------
32−
33−module Data.Generics.Product.Internal.List
34− ( GIsList (..)
35− , IndexList (..)
36− , List (..)
37− , type (++)
38− , Elem
39− , ListTuple (..)
40− , TupleToList
41− ) where
42−
43−#if __GLASGOW_HASKELL__ < 804
44−import Data.Semigroup
45−#endif
46−import GHC.TypeLits
47−
48−import Data.Kind (Type)
49−import GHC.Generics
50−import Data.Profunctor
51−import Data.Generics.Internal.Profunctor.Lens
52−import Data.Generics.Internal.Profunctor.Iso
53−
54−data List (as :: [(m, Type)]) where
55− Nil :: List '[]
56− (:>) :: a -> List as -> List ('(s, a) ': as)
57−
58−infixr 5 :>
59−
60−type family ((as :: [k]) ++ (bs :: [k])) :: [k] where
61− '[] ++ bs = bs
62− (a ': as) ++ bs = a ': as ++ bs
63−
64−instance Semigroup (List '[]) where
65− _ <> _ = Nil
66−
67−instance Monoid (List '[]) where
68− mempty = Nil
69− mappend _ _ = Nil
70−
71−instance (Semigroup a, Semigroup (List as)) => Semigroup (List ('(k, a) ': as)) where
72− (x :> xs) <> (y :> ys) = (x <> y) :> (xs <> ys)
73−
74−instance (Monoid a, Monoid (List as)) => Monoid (List ('(k, a) ': as)) where
75− mempty = mempty :> mempty
76− mappend (x :> xs) (y :> ys) = mappend x y :> mappend xs ys
77−
78−class Elem (as :: [(k, Type)]) (key :: k) (i :: Nat) a | as key -> i a
79−instance {-# OVERLAPPING #-} pos ~ 0 => Elem ('(key, a) ': xs) key pos a
80−instance (Elem xs key i a, pos ~ (i + 1)) => Elem (x ': xs) key pos a
81−
82−class GIsList
83− (m :: Type)
84− (f :: Type -> Type)
85− (g :: Type -> Type)
86− (as :: [(m, Type)])
87− (bs :: [(m, Type)]) | m f -> as, m g -> bs, bs f -> g, as g -> f where
88−
89− glist :: Iso (f x) (g x) (List as) (List bs)
90−
91− -- We define this reversed version, otherwise uses of `fromIso glist` are not
92− -- properly inlined by GHC 8.0.2.
93− -- This is not actually used.
94− glistR :: Iso (List bs) (List as) (g x) (f x)
95− glistR = fromIso (glist @m)
96−
97−instance
98− ( GIsList m l l' as as'
99− , GIsList m r r' bs bs'
100− , Appending List as bs cs as' bs' cs'
101− , cs ~ (as ++ bs)
102− , cs' ~ (as' ++ bs')
103− ) => GIsList m (l :*: r) (l' :*: r') cs cs' where
104−
105− glist = prodIso . pairing (glist @m) (glist @m) . appending
106− {-# INLINE glist #-}
107−
108−instance GIsList m f g as bs => GIsList m (M1 t meta f) (M1 t meta g) as bs where
109− glist = mIso . glist @m
110− {-# INLINE glist #-}
111−
112−instance {-# OVERLAPS #-}
113− GIsList Symbol
114− (S1 ('MetaSel ('Just field) u s i) (Rec0 a))
115− (S1 ('MetaSel ('Just field) u s i) (Rec0 b))
116− '[ '(field, a)] '[ '(field, b)] where
117− glist = mIso . kIso . singleton
118− {-# INLINE glist #-}
119−
120−instance GIsList Type (Rec0 a) (Rec0 a) '[ '(a, a)] '[ '(a, a)] where
121− glist = kIso . singleton
122− {-# INLINE glist #-}
123−
124−instance GIsList () (Rec0 a) (Rec0 b) '[ '( '(), a)] '[ '( '(), b)] where
125− glist = kIso . singleton
126− {-# INLINE glist #-}
127−
128−instance GIsList m U1 U1 '[] '[] where
129− glist = iso (const Nil) (const U1)
130− {-# INLINE glist #-}
131−
132−--------------------------------------------------------------------------------
133−-- | as ++ bs === cs
134−class Appending f (as :: [k]) bs cs (as' :: [k]) bs' cs' | as bs cs cs' -> as' bs', as' bs' cs cs' -> as bs, as bs -> cs, as' bs' -> cs' where
135− appending :: Iso (f as, f bs) (f as', f bs') (f cs) (f cs')
136−
137−-- | [] ++ bs === bs
138−instance Appending List '[] bs bs '[] bs' bs' where
139− appending = iso (\(_, b) -> b) (Nil,)
140−
141−-- | (a : as) ++ bs === (a : cs)
142−instance
143− Appending List as bs cs as' bs' cs' -- as ++ bs == cs
144− => Appending List ('(f, a) ': as) bs ('(f, a) ': cs) ('(f, a') ': as') bs' ('(f, a') ': cs') where
145− appending
146− = pairing (fromIso consing) id -- ((a, as), bs)
147− . assoc3 -- (a, (as, bs))
148− . pairing id appending -- (a, cs)
149− . consing -- (a : cs)
150−
151−singleton :: Iso a b (List '[ '(field, a)]) (List '[ '(field, b)])
152−singleton = iso (:> Nil) (\(x :> _) -> x)
153−
154−consing :: Iso (a, List as) (b, List bs) (List ('(f, a) ': as)) (List ('(f, b) ': bs))
155−consing = iso (\(x, xs) -> x :> xs) (\(x :> xs) -> (x, xs))
156−
157−--------------------------------------------------------------------------------
158−class IndexList (i :: Nat) as bs a b | i as -> a, i bs -> b, i as b -> bs, i bs a -> as where
159− point :: Lens (List as) (List bs) a b
160−
161−instance {-# OVERLAPPING #-}
162− ( as ~ ('(f, a) ': as')
163− , bs ~ ('(f, b) ': as')
164− ) => IndexList 0 as bs a b where
165− point = lens (\(x :> xs) -> (xs, x)) (\(xs, x') -> x' :> xs)
166− {-# INLINE point #-}
167−
168−instance
169− ( IndexList (n - 1) as' bs' a b
170− , as ~ ('(f, x) ': as')
171− , bs ~ ('(f, x) ': bs')
172− ) => IndexList n as bs a b where
173− point = fromIso consing . alongside id (point @(n-1)) . second'
174− {-# INLINE point #-}
175−
176−--------------------------------------------------------------------------------
177−-- * Convert tuples to/from HLists
178−
179−class ListTuple (tuple :: Type) (as :: [(k, Type)]) | as -> tuple where
180− type ListToTuple as :: Type
181− tupled :: Iso' (List as) tuple
182− tupled = iso listToTuple tupleToList
183−
184− tupleToList :: tuple -> List as
185− listToTuple :: List as -> tuple
186−
187−instance ListTuple () '[] where
188− type ListToTuple '[] = ()
189− tupleToList _ = Nil
190− listToTuple _ = ()
191−
192−instance ListTuple a '[ '(fa, a)] where
193− type ListToTuple '[ '(fa, a)] = a
194− tupleToList a
195− = a :> Nil
196− listToTuple (a :> Nil)
197− = a
198−
199−instance ListTuple (a, b) '[ '(fa, a), '(fb, b)] where
200− type ListToTuple '[ '(fa, a), '(fb, b)] = (a, b)
201− tupleToList (a, b)
202− = a :> b :> Nil
203− listToTuple (a :> b :> Nil)
204− = (a, b)
205−
206−instance ListTuple (a, b, c) '[ '(fa, a), '(fb, b), '(fc, c)] where
207− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c)] = (a, b, c)
208− tupleToList (a, b, c)
209− = a :> b :> c :> Nil
210− listToTuple (a :> b :> c :> Nil)
211− = (a, b, c)
212−
213−instance ListTuple (a, b, c, d) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d)] where
214− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d)] = (a, b, c, d)
215− tupleToList (a, b, c, d)
216− = a :> b :> c :> d:> Nil
217− listToTuple (a :> b :> c :> d :> Nil)
218− = (a, b, c, d)
219−
220−instance ListTuple (a, b, c, d, e) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e)] where
221− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e)] = (a, b, c, d, e)
222− tupleToList (a, b, c, d, e)
223− = a :> b :> c :> d:> e :> Nil
224− listToTuple (a :> b :> c :> d :> e :> Nil)
225− = (a, b, c, d, e)
226−
227−instance ListTuple (a, b, c, d, e, f) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f)] where
228− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f)] = (a, b, c, d, e, f)
229− tupleToList (a, b, c, d, e, f)
230− = a :> b :> c :> d:> e :> f :> Nil
231− listToTuple (a :> b :> c :> d :> e :> f :> Nil)
232− = (a, b, c, d, e, f)
233−
234−instance ListTuple (a, b, c, d, e, f, g) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g)] where
235− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g)] = (a, b, c, d, e, f, g)
236− tupleToList (a, b, c, d, e, f, g)
237− = a :> b :> c :> d:> e :> f :> g :> Nil
238− listToTuple (a :> b :> c :> d :> e :> f :> g :> Nil)
239− = (a, b, c, d, e, f, g)
240−
241−instance ListTuple (a, b, c, d, e, f, g, h) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h)] where
242− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h)] = (a, b, c, d, e, f, g, h)
243− tupleToList (a, b, c, d, e, f, g, h)
244− = a :> b :> c :> d:> e :> f :> g :> h :> Nil
245− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> Nil)
246− = (a, b, c, d, e, f, g, h)
247−
248−instance ListTuple (a, b, c, d, e, f, g, h, j) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j)] where
249− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j)] = (a, b, c, d, e, f, g, h, j)
250− tupleToList (a, b, c, d, e, f, g, h, j)
251− = a :> b :> c :> d:> e :> f :> g :> h :> j :> Nil
252− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> Nil)
253− = (a, b, c, d, e, f, g, h, j)
254−
255−instance ListTuple (a, b, c, d, e, f, g, h, j, k) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k)] where
256− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k)] = (a, b, c, d, e, f, g, h, j, k)
257− tupleToList (a, b, c, d, e, f, g, h, j, k)
258− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> Nil
259− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> Nil)
260− = (a, b, c, d, e, f, g, h, j, k)
261−
262−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l)] where
263− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l)] = (a, b, c, d, e, f, g, h, j, k, l)
264− tupleToList (a, b, c, d, e, f, g, h, j, k, l)
265− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> Nil
266− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> Nil)
267− = (a, b, c, d, e, f, g, h, j, k, l)
268−
269−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m)] where
270− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m)] = (a, b, c, d, e, f, g, h, j, k, l, m)
271− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m)
272− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> Nil
273− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> Nil)
274− = (a, b, c, d, e, f, g, h, j, k, l, m)
275−
276−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n)] where
277− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n)] = (a, b, c, d, e, f, g, h, j, k, l, m, n)
278− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n)
279− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> Nil
280− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> Nil)
281− = (a, b, c, d, e, f, g, h, j, k, l, m, n)
282−
283−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o)] where
284− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o)] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
285− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
286− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> Nil
287− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> Nil)
288− = (a, b, c, d, e, f, g, h, j, k, l, m, n, o)
289−
290−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p)] where
291− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p)] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
292− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
293− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> Nil
294− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> Nil)
295− = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p)
296−
297−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q)] where
298− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q)] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
299− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
300− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> Nil
301− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> Nil)
302− = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q)
303−
304−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q), '(fr, r)] where
305− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q), '(fr, r)] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
306− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
307− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> Nil
308− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> Nil)
309− = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r)
310−
311−instance ListTuple (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s) '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q), '(fr, r), '(fs, s)] where
312− type ListToTuple '[ '(fa, a), '(fb, b), '(fc, c), '(fd, d), '(fe, e), '(ff, f), '(fg, g), '(fh, h), '(fj, j), '(fk, k), '(fl, l), '(fm, m), '(fn, n), '(fo, o), '(fp, p), '(fq, q), '(fr, r), '(fs, s)] = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
313− tupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
314− = a :> b :> c :> d:> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> s :> Nil
315− listToTuple (a :> b :> c :> d :> e :> f :> g :> h :> j :> k :> l :> m :> n :> o :> p :> q :> r :> s :> Nil)
316− = (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s)
317−
318−type family TupleToList a where
319− TupleToList () = '[]
320− TupleToList (a, b) = '[ '( '(), a), '( '(), b)]
321− TupleToList (a, b, c) = '[ '( '(), a), '( '(), b), '( '(), c)]
322− TupleToList (a, b, c, d) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d)]
323− TupleToList (a, b, c, d, e) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e)]
324− TupleToList (a, b, c, d, e, f) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f)]
325− TupleToList (a, b, c, d, e, f, g) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g)]
326− TupleToList (a, b, c, d, e, f, g, h) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h)]
327− TupleToList (a, b, c, d, e, f, g, h, j) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j)]
328− TupleToList (a, b, c, d, e, f, g, h, j, k) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k)]
329− TupleToList (a, b, c, d, e, f, g, h, j, k, l) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l)]
330− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m)]
331− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n)]
332− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n), '( '(), o)]
333− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n), '( '(), o), '( '(), p)]
334− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n), '( '(), o), '( '(), p), '( '(), q)]
335− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n), '( '(), o), '( '(), p), '( '(), q), '( '(), r)]
336− TupleToList (a, b, c, d, e, f, g, h, j, k, l, m, n, o, p, q, r, s) = '[ '( '(), a), '( '(), b), '( '(), c), '( '(), d), '( '(), e), '( '(), f), '( '(), g), '( '(), h), '( '(), j), '( '(), k), '( '(), l), '( '(), m), '( '(), n), '( '(), o), '( '(), p), '( '(), q), '( '(), r), '( '(), s)]
337− TupleToList a = '[ '( '(), a)]
src/Data/Generics/Product/Internal/Positions.hs+1−1
@@ -17,7 +17,7 @@
1717-----------------------------------------------------------------------------
1818-- |
1919-- Module : Data.Generics.Product.Internal.Positions
20−-- Copyright : (C) 2017 Csongor Kiss
20+-- Copyright : (C) 2018 Csongor Kiss
2121-- License : BSD3
2222-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2323-- Stability : experimental
src/Data/Generics/Product/Internal/Subtype.hs+1−1
@@ -16,7 +16,7 @@
1616-----------------------------------------------------------------------------
1717-- |
1818-- Module : Data.Generics.Product.Internal.Subtype
19−-- Copyright : (C) 2017 Csongor Kiss
19+-- Copyright : (C) 2018 Csongor Kiss
2020-- License : BSD3
2121-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2222-- Stability : experimental
src/Data/Generics/Product/List.hsdeleted−78
@@ -1,78 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE FlexibleInstances #-}
4−{-# LANGUAGE FunctionalDependencies #-}
5−{-# LANGUAGE MonoLocalBinds #-}
6−{-# LANGUAGE ScopedTypeVariables #-}
7−{-# LANGUAGE TypeApplications #-}
8−{-# LANGUAGE TypeInType #-}
9−{-# LANGUAGE UndecidableInstances #-}
10−
11−-----------------------------------------------------------------------------
12−-- |
13−-- Module : Data.Generics.Product.List
14−-- Copyright : (C) 2017 Csongor Kiss
15−-- License : BSD3
16−-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
17−-- Stability : experimental
18−-- Portability : non-portable
19−--
20−-- Derive an isomorphism between a product type and a flat HList.
21−--
22−-----------------------------------------------------------------------------
23−
24−module Data.Generics.Product.List
25− ( IsList (..)
26− , IsRecord
27− , IsRecord'
28− ) where
29−
30−import Data.Generics.Product.Internal.List
31−import Data.Kind
32−import GHC.Generics
33−import GHC.TypeLits
34−import Data.Generics.Internal.Profunctor.Iso
35−
36−class IsList
37− (m :: Type)
38− (f :: Type)
39− (g :: Type)
40− (as :: [(m, Type)])
41− (bs :: [(m, Type)]) | m f -> as, m g -> bs where
42− list :: Iso f g (List as) (List bs)
43−
44−instance
45− ( Generic f
46− , Generic g
47− , GIsList m (Rep f) (Rep g) as bs
48− ) => IsList m f g as bs where
49− list = repIso . glist @m
50− {-# INLINE list #-}
51−
52−class IsList Symbol f g as bs => IsRecord f g (as :: [(Symbol, Type)]) (bs :: [(Symbol, Type)]) | f -> as, g -> bs
53−instance IsList Symbol f g as bs => IsRecord f g as bs
54−
55−class IsRecord f f as as => IsRecord' f (as :: [(Symbol, Type)]) | f -> as
56−instance IsRecord f f as as => IsRecord' f as
57−
58−-- example (TODO: move elsewhere)
59−--class PrintRecord (rl :: [(Symbol, Type)]) where
60−-- printRecord' :: List rl -> String
61−--
62−--instance PrintRecord '[] where
63−-- printRecord' _ = ""
64−--
65−--instance (KnownSymbol field, Show a, PrintRecord xs) => PrintRecord ('(field, a) ': xs) where
66−-- printRecord' (x :> xs) = show x ++ ", " ++ printRecord' xs
67−--
68−--printRecord :: (IsRecord' rec rl, PrintRecord rl) => rec -> String
69−--printRecord rec = printRecord' (rec ^. list)
70−--
71−--data MyRecord = MyRecord
72−-- { field1 :: Int
73−-- , field2 :: String
74−-- , field3 :: Bool
75−-- } deriving Generic
76−--
77−-- >>> printRecord (MyRecord 10 "hello" False)
78−-- "10, \"hello\", False, "
src/Data/Generics/Product/Positions.hs+1−1
@@ -19,7 +19,7 @@
1919-----------------------------------------------------------------------------
2020-- |
2121-- Module : Data.Generics.Product.Positions
22−-- Copyright : (C) 2017 Csongor Kiss
22+-- Copyright : (C) 2018 Csongor Kiss
2323-- License : BSD3
2424-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2525-- Stability : experimental
src/Data/Generics/Product/Subtype.hs+1−1
@@ -15,7 +15,7 @@
1515-----------------------------------------------------------------------------
1616-- |
1717-- Module : Data.Generics.Product.Subtype
18−-- Copyright : (C) 2017 Csongor Kiss
18+-- Copyright : (C) 2018 Csongor Kiss
1919-- License : BSD3
2020-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2121-- Stability : experimental
src/Data/Generics/Product/Typed.hs+1−1
@@ -14,7 +14,7 @@
1414-----------------------------------------------------------------------------
1515-- |
1616-- Module : Data.Generics.Product.Typed
17−-- Copyright : (C) 2017 Csongor Kiss
17+-- Copyright : (C) 2018 Csongor Kiss
1818-- License : BSD3
1919-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2020-- Stability : experimental
src/Data/Generics/Product/Types.hs+1−1
@@ -16,7 +16,7 @@
1616-----------------------------------------------------------------------------
1717-- |
1818-- Module : Data.Generics.Product.Types
19−-- Copyright : (C) 2017 Csongor Kiss
19+-- Copyright : (C) 2018 Csongor Kiss
2020-- License : BSD3
2121-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2222-- Stability : experimental
src/Data/Generics/Sum.hs+1−1
@@ -1,7 +1,7 @@
11-----------------------------------------------------------------------------
22-- |
33-- Module : Data.Generics.Sum
4−-- Copyright : (C) 2017 Csongor Kiss
4+-- Copyright : (C) 2018 Csongor Kiss
55-- License : BSD3
66-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
77-- Stability : experimental
src/Data/Generics/Sum/Any.hs+1−1
@@ -11,7 +11,7 @@
1111-----------------------------------------------------------------------------
1212-- |
1313-- Module : Data.Generics.Sum.Any
14−-- Copyright : (C) 2017 Csongor Kiss
14+-- Copyright : (C) 2018 Csongor Kiss
1515-- License : BSD3
1616-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1717-- Stability : experimental
src/Data/Generics/Sum/Constructors.hs+1−1
@@ -15,7 +15,7 @@
1515-----------------------------------------------------------------------------
1616-- |
1717-- Module : Data.Generics.Sum.Constructors
18−-- Copyright : (C) 2017 Csongor Kiss
18+-- Copyright : (C) 2018 Csongor Kiss
1919-- License : BSD3
2020-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2121-- Stability : experimental
src/Data/Generics/Sum/Internal/Constructors.hs+5−6
@@ -14,7 +14,7 @@
1414-----------------------------------------------------------------------------
1515-- |
1616-- Module : Data.Generics.Sum.Internal.Constructors
17−-- Copyright : (C) 2017 Csongor Kiss
17+-- Copyright : (C) 2018 Csongor Kiss
1818-- License : BSD3
1919-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2020-- Stability : experimental
@@ -30,11 +30,10 @@ module Data.Generics.Sum.Internal.Constructors
3030 ) where
3131
3232import Data.Generics.Internal.Families
33−import Data.Generics.Product.Internal.List
33+import Data.Generics.Product.Internal.HList
3434
3535import GHC.Generics
3636import GHC.TypeLits (Symbol)
37−import Data.Kind
3837import Data.Generics.Internal.Profunctor.Lens
3938import Data.Generics.Internal.Profunctor.Iso
4039import Data.Generics.Internal.Profunctor.Prism
@@ -47,13 +46,13 @@ class GAsConstructor (ctor :: Symbol) s t a b | ctor s -> a, ctor t -> b where
4746type GAsConstructor' ctor s a = GAsConstructor ctor s s a a
4847
4948instance
50− ( GIsList Type f f as as
51− , GIsList Type g g bs bs
49+ ( GIsList f f as as
50+ , GIsList g g bs bs
5251 , ListTuple a as
5352 , ListTuple b bs
5453 ) => GAsConstructor ctor (M1 C ('MetaCons ctor fixity fields) f) (M1 C ('MetaCons ctor fixity fields) g) a b where
5554
56− _GCtor = prism (M1 . view (fromIso (glist @Type)) . tupleToList) (Right . listToTuple . view (glist @Type) . unM1)
55+ _GCtor = prism (M1 . view (fromIso glist) . tupleToList) (Right . listToTuple . view glist . unM1)
5756 {-# INLINE[0] _GCtor #-}
5857
5958
src/Data/Generics/Sum/Internal/Subtype.hs+8−8
@@ -14,7 +14,7 @@
1414-----------------------------------------------------------------------------
1515-- |
1616-- Module : Data.Generics.Sum.Internal.Subtype
17−-- Copyright : (C) 2017 Csongor Kiss
17+-- Copyright : (C) 2018 Csongor Kiss
1818-- License : BSD3
1919-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
2020-- Stability : experimental
@@ -28,7 +28,7 @@ module Data.Generics.Sum.Internal.Subtype
2828 ( GAsSubtype (..)
2929 ) where
3030
31−import Data.Generics.Product.Internal.List
31+import Data.Generics.Product.Internal.HList
3232import Data.Generics.Sum.Internal.Typed
3333
3434import Data.Kind
@@ -46,7 +46,7 @@ instance
4646 ( GSplash sub sup
4747 , GDowncast sub sup
4848 ) => GAsSubtype sub sup where
49− _GSub f = (prism _GSplash _GDowncast) f
49+ _GSub f = prism _GSplash _GDowncast f
5050 {-# INLINE[0] _GSub #-}
5151
5252--------------------------------------------------------------------------------
@@ -60,10 +60,10 @@ instance (GSplash a sup, GSplash b sup) => GSplash (a :+: b) sup where
6060 {-# INLINE[0] _GSplash #-}
6161
6262instance
63− ( GIsList () subf subf as as
63+ ( GIsList subf subf as as
6464 , GAsType supf as
6565 ) => GSplash (C1 meta subf) supf where
66− _GSplash p = build ((_GTyped . fromIso (glist @()) . fromIso mIso)) p
66+ _GSplash p = build (_GTyped . fromIso (mIso . glist)) p
6767 {-# INLINE[0] _GSplash #-}
6868
6969instance GSplash sub sup => GSplash (D1 c sub) sup where
@@ -76,7 +76,7 @@ class GDowncast sub sup where
7676 _GDowncast :: sup x -> Either (sup x) (sub x)
7777
7878instance
79− ( GIsList () sup sup as as
79+ ( GIsList sup sup as as
8080 , GDowncastC (HasPartialTypeP as sub) sub sup
8181 ) => GDowncast sub (C1 m sup) where
8282 _GDowncast (M1 m) = case _GDowncastC @(HasPartialTypeP as sub) m of
@@ -108,8 +108,8 @@ instance GDowncastC 'False sub sup where
108108
109109instance
110110 ( GAsType sub subl
111− , GIsList () sup sup subl subl
111+ , GIsList sup sup subl subl
112112 ) => GDowncastC 'True sub sup where
113− _GDowncastC sup = Right (build (_GTyped . fromIso (glist @())) sup)
113+ _GDowncastC sup = Right (build (_GTyped . fromIso glist) sup)
114114 {-# INLINE[0] _GDowncastC #-}
115115
src/Data/Generics/Sum/Internal/Typed.hs+8−8
@@ -13,7 +13,7 @@
1313-----------------------------------------------------------------------------
1414-- |
1515-- Module : Data.Generics.Sum.Internal.Typed
16−-- Copyright : (C) 2017 Csongor Kiss
16+-- Copyright : (C) 2018 Csongor Kiss
1717-- License : BSD3
1818-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1919-- Stability : experimental
@@ -32,13 +32,13 @@ import GHC.Generics
3232import Data.Tagged
3333
3434import Data.Generics.Internal.Families
35−import Data.Generics.Product.Internal.List
35+import Data.Generics.Product.Internal.HList
3636import Data.Generics.Internal.Profunctor.Iso
3737import Data.Generics.Internal.Profunctor.Prism
3838
3939-- |As 'AsType' but over generic representations as defined by "GHC.Generics".
40−class GAsType (f :: Type -> Type) (as :: [((), Type)]) where
41− _GTyped :: Prism (f x) (f x) (List as) (List as)
40+class GAsType (f :: Type -> Type) (as :: [Type]) where
41+ _GTyped :: Prism (f x) (f x) (HList as) (HList as)
4242-- We create this specialised version as we use it in the subtype prism
4343-- If we don't create it, the opportunity for specialisation is only
4444-- created after specialisation happens, I think a late specialisation pass
@@ -47,9 +47,9 @@ class GAsType (f :: Type -> Type) (as :: [((), Type)]) where
4747
4848
4949instance
50− ( GIsList () f f as as
50+ ( GIsList f f as as
5151 ) => GAsType (M1 C meta f) as where
52− _GTyped = mIso . glist @()
52+ _GTyped = mIso . glist
5353 {-# INLINE[0] _GTyped #-}
5454
5555instance GSumAsType (HasPartialTypeP a l) l r a => GAsType (l :+: r) a where
@@ -60,8 +60,8 @@ instance GAsType f a => GAsType (M1 D meta f) a where
6060 _GTyped = mIso . _GTyped
6161 {-# INLINE[0] _GTyped #-}
6262
63−class GSumAsType (contains :: Bool) l r (a :: [((), Type)]) where
64− _GSumTyped :: Prism ((l :+: r) x) ((l :+: r) x) (List a) (List a)
63+class GSumAsType (contains :: Bool) l r (a :: [Type]) where
64+ _GSumTyped :: Prism ((l :+: r) x) ((l :+: r) x) (HList a) (HList a)
6565
6666instance GAsType l a => GSumAsType 'True l r a where
6767 _GSumTyped = left . _GTyped
src/Data/Generics/Sum/Subtype.hs+1−1
@@ -11,7 +11,7 @@
1111-----------------------------------------------------------------------------
1212-- |
1313-- Module : Data.Generics.Sum.Subtype
14−-- Copyright : (C) 2017 Csongor Kiss
14+-- Copyright : (C) 2018 Csongor Kiss
1515-- License : BSD3
1616-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1717-- Stability : experimental
src/Data/Generics/Sum/Typed.hs+2−2
@@ -13,7 +13,7 @@
1313-----------------------------------------------------------------------------
1414-- |
1515-- Module : Data.Generics.Sum.Typed
16−-- Copyright : (C) 2017 Csongor Kiss
16+-- Copyright : (C) 2018 Csongor Kiss
1717-- License : BSD3
1818-- Maintainer : Csongor Kiss <kiss.csongor.kiss@gmail.com>
1919-- Stability : experimental
@@ -37,7 +37,7 @@ import Data.Generics.Sum.Internal.Typed
3737
3838import Data.Generics.Internal.Families
3939import Data.Generics.Internal.Void
40−import Data.Generics.Product.Internal.List
40+import Data.Generics.Product.Internal.HList
4141import Data.Generics.Internal.VL.Prism
4242import Data.Generics.Internal.Profunctor.Iso
4343import Data.Generics.Internal.Profunctor.Prism (prismPRavel)