summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphadej <>2021-02-23 09:20:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2021-02-23 09:20:00 (GMT)
commit51430bf93610b2a5d25739d24c3b0a2b79b118fa (patch)
treeadf70aa8404e579a7c18c2a999d98606a613172a
parent5bd624501b9de5224c123f9c0c742e77c7df6dc8 (diff)
version 0.4.0.2HEAD0.4.0.2master
-rw-r--r--CHANGES.md4
-rw-r--r--src/Data/Strict/Lens.hs48
-rw-r--r--strict-lens.cabal5
3 files changed, 38 insertions, 19 deletions
diff --git a/CHANGES.md b/CHANGES.md
index fc85265..d05eb80 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,7 @@
+## 0.4.0.2
+
+- lens-5 support
+
## 0.4.0.1
- Fix Each These instance
diff --git a/src/Data/Strict/Lens.hs b/src/Data/Strict/Lens.hs
index 662521b..713853d 100644
--- a/src/Data/Strict/Lens.hs
+++ b/src/Data/Strict/Lens.hs
@@ -21,47 +21,56 @@ module Data.Strict.Lens (
) where
-import Control.Applicative (pure, (<$>), (<*>))
+import Control.Applicative (pure, (<$>))
import Prelude (Int, flip, ($), (.))
-- Lazy variants
import qualified Prelude as L
-import qualified Control.Lens as L
-import Control.Lens (Each (..), Field1 (..), Field2 (..),
- Index, Prism, Prism', Swapped (..),
- Traversal, indexed, iso, prism, prism',
- (<&>))
+import Control.Lens (Index, Prism, Prism', Traversal, prism,
+ prism')
import Data.Strict (Either (..), Maybe (..), Pair (..),
- Strict (..), These (..), either, maybe,
- swap, these)
+ These (..), either, maybe, these)
+
+#if !MIN_VERSION_lens(5,0,0)
+import Control.Applicative ((<*>))
+import Control.Lens (Each (..), Field1 (..), Field2 (..),
+ Swapped (..), indexed, iso, (<&>))
+import qualified Control.Lens as L
+import Data.Strict (Strict (..), swap)
+#endif
-------------------------------------------------------------------------------
-- Tuple
-------------------------------------------------------------------------------
-instance L.Strict (a, b) (Pair a b) where
- strict = iso toStrict toLazy
-
+#if !MIN_VERSION_lens(5,0,0)
instance Field1 (Pair a b) (Pair a' b) a a' where
_1 k (a :!: b) = indexed k (0 :: Int) a <&> \a' -> (a' :!: b)
instance Field2 (Pair a b) (Pair a b') b b' where
_2 k (a :!: b) = indexed k (1 :: Int) b <&> \b' -> (a :!: b')
+instance L.Strict (a, b) (Pair a b) where
+ strict = iso toStrict toLazy
+
instance Swapped Pair where
swapped = iso swap swap
-type instance Index (Pair a b) = Int
instance (a~a', b~b') => Each (Pair a a') (Pair b b') a b where
each f ~(a :!: b) = (:!:) <$> f a <*> f b
{-# INLINE each #-}
+#endif
+
+-- TODO: this should be removed. Probably.
+type instance Index (Pair a b) = Int
-------------------------------------------------------------------------------
-- Either
-------------------------------------------------------------------------------
+#if !MIN_VERSION_lens(5,0,0)
instance L.Strict (L.Either a b) (Either a b) where
strict = iso toStrict toLazy
@@ -71,6 +80,7 @@ instance Swapped Either where
instance (a ~ a', b ~ b') => Each (Either a a') (Either b b') a b where
each f (Left x) = Left <$> f x
each f (Right x) = Right <$> f x
+#endif
-- | Analogous to 'Control.Lens.Prism._Left' in "Control.Lens.Prism".
_Left :: Prism (Either a c) (Either b c) a b
@@ -84,10 +94,12 @@ _Right = prism Right $ either (L.Left . Left) L.Right
-- Maybe
-------------------------------------------------------------------------------
+#if !MIN_VERSION_lens(5,0,0)
instance L.Strict (L.Maybe a) (Maybe a) where
strict = iso toStrict toLazy
instance Each (Maybe a) (Maybe b) a b
+#endif
-- | Analogous to 'Control.Lens.Prism._Just' in "Control.Lens.Prism"
_Just :: Prism (Maybe a) (Maybe b) a b
@@ -101,13 +113,20 @@ _Nothing = prism' (L.const Nothing) $ maybe (L.Just ()) (L.const L.Nothing)
-- These
-------------------------------------------------------------------------------
+#if !MIN_VERSION_lens(5,0,0)
instance Swapped These where
swapped = iso swapThese swapThese
+swapThese :: These a b -> These b a
+swapThese (This a) = That a
+swapThese (That b) = This b
+swapThese (These a b) = These b a
+
instance (a ~ a', b ~ b') => Each (These a a') (These b b') a b where
each f (This a) = This <$> f a
each f (That b) = That <$> f b
each f (These a b) = These <$> f a <*> f b
+#endif
-- | A 'Control.Lens.Traversal' of the first half of a 'These', suitable for use with "Control.Lens".
--
@@ -156,8 +175,3 @@ _That = prism That (these (L.Left . This) L.Right (\x y -> L.Left $ These x y))
-- /Note:/ cannot change type.
_These :: Prism' (These a b) (a, b)
_These = prism (\(a,b) -> These a b) (these (L.Left . This) (L.Left . That) (\x y -> L.Right (x, y)))
-
-swapThese :: These a b -> These b a
-swapThese (This a) = That a
-swapThese (That b) = This b
-swapThese (These a b) = These b a
diff --git a/strict-lens.cabal b/strict-lens.cabal
index 07e2805..857a3e8 100644
--- a/strict-lens.cabal
+++ b/strict-lens.cabal
@@ -1,5 +1,5 @@
name: strict-lens
-version: 0.4.0.1
+version: 0.4.0.2
synopsis: Lenses for types in strict package
category: Data, Lenses
description: Lenses for types in strict package.
@@ -28,6 +28,7 @@ tested-with:
|| ==8.6.5
|| ==8.8.3
|| ==8.10.1
+ || ==9.0.1
extra-source-files: CHANGES.md
@@ -47,7 +48,7 @@ library
build-depends:
base >=4.5 && <5
- , lens >=4.19.2 && <4.20
+ , lens >=4.19.2 && <5.1
, strict >=0.4 && <0.4.1
hs-source-dirs: src