@@ -1,4 +1,4 @@
1−{-# OPTIONS_GHC -O -fplugin GHC.Proof.Plugin #-}
1+{-# OPTIONS_GHC -O -fplugin Test.Inspection.Plugin #-}
3{-# LANGUAGE AllowAmbiguousTypes #-}
3{-# LANGUAGE AllowAmbiguousTypes #-}
4{-# LANGUAGE DataKinds #-}
4{-# LANGUAGE DataKinds #-}
@@ -8,12 +8,16 @@
8{-# LANGUAGE RankNTypes #-}
8{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE TypeApplications #-}
10{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE TemplateHaskell #-}
12module Main where
14module Main where
14import GHC.Generics
16import GHC.Generics
15import Data.Generics.Product
17import Data.Generics.Product
16−import GHC.Proof
18+#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
19+import Test.Inspection
18main :: IO ()
22main :: IO ()
19main = putStrLn "Hello world"
23main = putStrLn "Hello world"
@@ -42,19 +46,28 @@ subtypeLensManual f record
43--------------------------------------------------------------------------------
47--------------------------------------------------------------------------------
45−-- The ghc-proofs plugin checks that the following equalities hold, by checking
49+-- The inspection-testing plugin checks that the following equalities hold, by
46−-- that the LHSs and the RHSs are CSEd. This also means that the runtime
50+-- checking that the LHSs and the RHSs are CSEd. This also means that the
47−-- characteristics of the derived lenses is the same as the manually written
51+-- runtime characteristics of the derived lenses is the same as the manually
48−-- ones above.
52+-- written ones above.
50−fieldP :: Proof
54+fieldALensName :: Lens' Record Int
51−fieldP = L fieldALensManual === L (field @"fieldA")
55+fieldALensName = field @"fieldA"
53−typedP :: Proof
57+fieldALensType :: Lens' Record Int
54−typedP = L fieldALensManual === L (typed @Int)
58+fieldALensType = typed @Int
56−posP :: Proof
60+fieldALensPos :: Lens' Record Int
57−posP = L fieldALensManual === L (position @1)
61+fieldALensPos = position @1
59−subtypeP :: Proof
63+subtypeLensGeneric :: Lens' Record Record2
64+subtypeLensGeneric = super
66+#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
67+-- It turns out that these equalities only hold with ghc-8.2 or newer,
68+-- probably due to improvements to CSE
69+inspect $ 'fieldALensManual === 'fieldALensName
70+inspect $ 'fieldALensManual === 'fieldALensType
71+inspect $ 'fieldALensManual === 'fieldALensPos
60−subtypeP = L subtypeLensManual === L super
72+inspect $ 'subtypeLensManual === 'subtypeLensGeneric