summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs')
-rw-r--r--testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs b/testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs
new file mode 100644
index 0000000000..fb727b003b
--- /dev/null
+++ b/testsuite/tests/simplCore/should_compile/T18346/MiniLens.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE RankNTypes #-}
+
+module MiniLens ((^.), Getting, Lens', lens, view) where
+
+import Data.Functor.Const (Const(..))
+
+type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
+
+type Lens' s a = Lens s s a a
+
+lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
+lens sa sbt afb s = sbt s <$> afb (sa s)
+{-# INLINE lens #-}
+
+type Getting r s a = (a -> Const r a) -> s -> Const r s
+
+view :: Getting a s a -> s -> a
+view l = getConst . l Const
+{-# INLINE view #-}
+
+(^.) :: s -> Getting a s a -> a
+s ^. l = getConst (l Const s)
+{-# INLINE (^.) #-}