@@ -1,3 +1,4 @@
1+{-# LANGUAGE TypeFamilies #-}
1{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
@@ -28,10 +29,11 @@ module Data.Generics.Product.Param
28 , HasParam (..)
29 , HasParam (..)
31−import GHC.TypeLits (Nat)
32+import GHC.TypeLits
32import Data.Generics.Internal.Void
33import Data.Generics.Internal.Void
33import Data.Generics.Internal.Families.Changing
34import Data.Generics.Internal.Families.Changing
34import Data.Generics.Internal.VL.Traversal
35import Data.Generics.Internal.VL.Traversal
36+import Data.Generics.Internal.VL.Lens
36import GHC.Generics
38import GHC.Generics
37import Data.Kind
39import Data.Kind
@@ -47,12 +49,27 @@ instance
47 -- TODO: merge the old 'Changing' code with 'GenericN'
49 -- TODO: merge the old 'Changing' code with 'GenericN'
48 , s ~ Infer t (P n b 'PTag) a
50 , s ~ Infer t (P n b 'PTag) a
49 , t ~ Infer s (P n a 'PTag) b
51 , t ~ Infer s (P n a 'PTag) b
52+ , Error ((ArgCount s) <=? n) n (ArgCount s) s
50 , GHasParam n (RepN s) (RepN t) a b
53 , GHasParam n (RepN s) (RepN t) a b
51 ) => HasParam n s t a b where
54 ) => HasParam n s t a b where
53 param = confusing (\f s -> toN <$> gparam @n f (fromN s))
56 param = confusing (\f s -> toN <$> gparam @n f (fromN s))
54 {-# INLINE param #-}
57 {-# INLINE param #-}
59+type family Error (b :: Bool) (expected :: Nat) (actual :: Nat) (s :: Type) :: Constraint where
63+ Error 'True expected actual typ
65+ ( 'Text "Expected a type with at least "
66+ ':<>: 'ShowType (expected + 1)
67+ ':<>: 'Text " parameters, but "
69+ ':<>: 'Text " only has "
70+ ':<>: 'ShowType actual
56instance {-# OVERLAPPING #-} HasParam p (Void1 a) (Void1 b) a b where
73instance {-# OVERLAPPING #-} HasParam p (Void1 a) (Void1 b) a b where
57 param = undefined
74 param = undefined