on master help sign in
Merge pull request #67 from Lysxia/uninteresting-word

Declare Data.Word and Data.Int types as uninteresting

commit30caabbb3623c41c80ddef57fa7e966043667e37 authorCsongor Kiss <kiss.csongor.kiss@gmail.com> dateWed 10 Oct 2018, 18:34 (8 years ago) parent238b01dbac1bbb
4 files changed+39−3
generic-lens.cabal+1−1 src/Data/Generics/Internal/VL/Lens.hs+4 src/Data/Generics/Product/Types.hs+22−2 test/Test63.hs+12
generic-lens.cabal+1−1
@@ -97,7 +97,7 @@ test-suite generic-lens-test
9797 type: exitcode-stdio-1.0
9898 hs-source-dirs: test
9999 main-is: Spec.hs
100− other-modules: Util Test24 Test25 Test40 Test62
100+ other-modules: Util Test24 Test25 Test40 Test62 Test63
101101
102102 build-depends: base >= 4.9 && <= 5.0
103103 , generic-lens
src/Data/Generics/Internal/VL/Lens.hs+4
@@ -22,6 +22,7 @@
2222module Data.Generics.Internal.VL.Lens where
2323
2424import Control.Applicative (Const(..))
25+import Data.Coerce (coerce)
2526import Data.Functor.Identity (Identity(..))
2627import Data.Generics.Internal.Profunctor.Lens (ALens (..), idLens)
2728
@@ -47,6 +48,9 @@ infixr 4 .~
4748set :: Lens s t a b -> b -> s -> t
4849set l x = l .~ x
4950
51+over :: ((a -> Identity b) -> s -> Identity t) -> (a -> b) -> s -> t
52+over = coerce
53+
5054lens2lensvl :: ALens a b s t -> Lens s t a b
5155lens2lensvl (ALens _get _set) =
5256 \f x ->
src/Data/Generics/Product/Types.hs+22−2
@@ -35,6 +35,8 @@ module Data.Generics.Product.Types
3535 ) where
3636
3737import Data.Kind
38+import Data.Int (Int8, Int16, Int32, Int64)
39+import Data.Word (Word, Word8, Word16, Word32, Word64)
3840
3941import GHC.Generics
4042import Data.Generics.Internal.VL.Traversal
@@ -76,9 +78,18 @@ instance {-# OVERLAPPING #-} HasTypes Bool a
7678instance {-# OVERLAPPING #-} HasTypes Char a
7779instance {-# OVERLAPPING #-} HasTypes Double a
7880instance {-# OVERLAPPING #-} HasTypes Float a
79−instance {-# OVERLAPPING #-} HasTypes Int a
8081instance {-# OVERLAPPING #-} HasTypes Integer a
8182instance {-# OVERLAPPING #-} HasTypes Ordering a
83+instance {-# OVERLAPPING #-} HasTypes Int a
84+instance {-# OVERLAPPING #-} HasTypes Int8 a
85+instance {-# OVERLAPPING #-} HasTypes Int16 a
86+instance {-# OVERLAPPING #-} HasTypes Int32 a
87+instance {-# OVERLAPPING #-} HasTypes Int64 a
88+instance {-# OVERLAPPING #-} HasTypes Word a
89+instance {-# OVERLAPPING #-} HasTypes Word8 a
90+instance {-# OVERLAPPING #-} HasTypes Word16 a
91+instance {-# OVERLAPPING #-} HasTypes Word32 a
92+instance {-# OVERLAPPING #-} HasTypes Word64 a
8293
8394--------------------------------------------------------------------------------
8495
@@ -135,8 +146,17 @@ type family Interesting' f (a :: Type) (seen :: [Type]) :: ([Type], Bool) where
135146 Interesting' (Rec0 Char) _ seen = '(seen ,'False)
136147 Interesting' (Rec0 Double) _ seen = '(seen ,'False)
137148 Interesting' (Rec0 Float) _ seen = '(seen ,'False)
138− Interesting' (Rec0 Int) _ seen = '(seen ,'False)
139149 Interesting' (Rec0 Integer) _ seen = '(seen ,'False)
150+ Interesting' (Rec0 Int) _ seen = '(seen ,'False)
151+ Interesting' (Rec0 Int8) _ seen = '(seen ,'False)
152+ Interesting' (Rec0 Int16) _ seen = '(seen ,'False)
153+ Interesting' (Rec0 Int32) _ seen = '(seen ,'False)
154+ Interesting' (Rec0 Int64) _ seen = '(seen ,'False)
155+ Interesting' (Rec0 Word) _ seen = '(seen ,'False)
156+ Interesting' (Rec0 Word8) _ seen = '(seen ,'False)
157+ Interesting' (Rec0 Word16) _ seen = '(seen ,'False)
158+ Interesting' (Rec0 Word32) _ seen = '(seen ,'False)
159+ Interesting' (Rec0 Word64) _ seen = '(seen ,'False)
140160 Interesting' (Rec0 r) t seen
141161 = InterestingUnless (Elem r seen) (Rep r) t r seen
142162 Interesting' _ _ seen
test/Test63.hsnew file+12
@@ -0,0 +1,12 @@
1+{-# LANGUAGE DataKinds, DeriveGeneric, TypeApplications #-}
2+module Test63 (example) where
3+import Data.Generics.Product (types)
4+import Data.Generics.Internal.VL.Lens (over)
5+import Data.Word (Word32)
6+import GHC.Generics (Generic)
7+
8+data Record = Record {field1 :: Word32, field2 :: Int}
9+ deriving (Generic, Show)
10+
11+example :: Record
12+example = over (types @Int) (+1) (Record 0 0)