vec-optics 0.3 → 0.4
raw patch · 5 files changed
+49/−22 lines, 5 filesdep ~basedep ~findep ~optics-core
Dependency ranges changed: base, fin, optics-core, vec
Files
- src/Data/Vec/DataFamily/SpineStrict/Optics.hs +16/−10
- src/Data/Vec/Lazy/Inline/Optics.hs +8/−5
- src/Data/Vec/Lazy/Optics.hs +6/−0
- src/Data/Vec/Pull/Optics.hs +5/−0
- vec-optics.cabal +14/−7
src/Data/Vec/DataFamily/SpineStrict/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -32,6 +33,9 @@ -- >>> :set -XScopedTypeVariables -- >>> import Prelude (Maybe (..), Char, Bool (..)) -- >>> import Optics.Core (over, view, set, (%), review, preview)+-- >>> import Data.Fin (Fin (..))+-- >>> import qualified Data.Type.Nat as N+-- >>> import Data.Vec.DataFamily.SpineStrict type LensLikeVL f s t a b = (a -> f b) -> s -> f t type LensLikeVL' f s a = LensLikeVL f s s a a@@ -74,7 +78,7 @@ {-# INLINE tailVL #-} -- | An 'I.Iso' from 'toPull' and 'fromPull'.-_Pull :: N.InlineInduction n => L.Iso (Vec n a) (Vec n b) (P.Vec n a) (P.Vec n b)+_Pull :: N.SNatI n => L.Iso (Vec n a) (Vec n b) (P.Vec n a) (P.Vec n b) _Pull = L.iso toPull fromPull -- | Prism from list.@@ -88,7 +92,7 @@ -- >>> review _Vec (True ::: False ::: VNil) -- [True,False] ---_Vec :: N.InlineInduction n => L.Prism' [a] (Vec n a)+_Vec :: N.SNatI n => L.Prism' [a] (Vec n a) _Vec = L.prism' toList fromList -- | Index lens.@@ -99,12 +103,12 @@ -- >>> set (ix (FS FZ)) 'x' ('a' ::: 'b' ::: 'c' ::: VNil) -- 'a' ::: 'x' ::: 'c' ::: VNil ---ix :: forall n a. N.InlineInduction n => Fin n -> L.Lens' (Vec n a) a+ix :: forall n a. N.SNatI n => Fin n -> L.Lens' (Vec n a) a ix i = L.lensVL (ixVL i) {-# INLINE ix #-} -ixVL :: forall n f a. (N.InlineInduction n, Functor f) => Fin n -> LensLikeVL' f (Vec n a) a-ixVL = getIxLens $ N.inlineInduction1 start step where+ixVL :: forall n f a. (N.SNatI n, Functor f) => Fin n -> LensLikeVL' f (Vec n a) a+ixVL = getIxLens $ N.induction1 start step where start :: IxLens f 'Z a start = IxLens F.absurd @@ -120,24 +124,26 @@ -- Instances ------------------------------------------------------------------------------- -instance N.InlineInduction n => L.FunctorWithIndex (Fin n) (Vec n) where+#if !MIN_VERSION_optics_core(0,4,0)+instance N.SNatI n => L.FunctorWithIndex (Fin n) (Vec n) where imap = imap -instance N.InlineInduction n => L.FoldableWithIndex (Fin n) (Vec n) where+instance N.SNatI n => L.FoldableWithIndex (Fin n) (Vec n) where ifoldMap = ifoldMap ifoldr = ifoldr -instance N.InlineInduction n => L.TraversableWithIndex (Fin n) (Vec n) where+instance N.SNatI n => L.TraversableWithIndex (Fin n) (Vec n) where itraverse = itraverse+#endif -instance N.InlineInduction n => L.Each (Fin n) (Vec n a) (Vec n b) a b where+instance N.SNatI n => L.Each (Fin n) (Vec n a) (Vec n b) a b where type instance L.Index (Vec n a) = Fin n type instance L.IxValue (Vec n a) = a -- | 'Vec' doesn't have 'L.At' instance, as we __cannot__ remove value from 'Vec'. -- See 'ix' in "Data.Vec.DataFamily.SpineStrict" module for an 'L.Lens' (not 'L.Traversal').-instance N.InlineInduction n => L.Ixed (Vec n a) where+instance N.SNatI n => L.Ixed (Vec n a) where type IxKind (Vec n a) = L.A_Lens ix = ix
src/Data/Vec/Lazy/Inline/Optics.hs view
@@ -28,8 +28,11 @@ -- $setup -- >>> :set -XScopedTypeVariables+-- >>> import Data.Fin (Fin (..))+-- >>> import Data.Vec.Lazy.Inline -- >>> import Prelude (Maybe (..), Char, Bool (..)) -- >>> import Optics.Core (over, view, set, (%), review, preview)+-- >>> import qualified Data.Type.Nat as N type LensLikeVL f s t a b = (a -> f b) -> s -> f t type LensLikeVL' f s a = LensLikeVL f s s a a@@ -46,12 +49,12 @@ -- >>> set (ix (FS FZ)) 'x' ('a' ::: 'b' ::: 'c' ::: VNil) -- 'a' ::: 'x' ::: 'c' ::: VNil ---ix :: forall n a. N.InlineInduction n => Fin n -> L.Lens' (Vec n a) a+ix :: forall n a. N.SNatI n => Fin n -> L.Lens' (Vec n a) a ix i = L.lensVL (ixVL i) {-# INLINE ix #-} -ixVL :: forall n f a. (N.InlineInduction n, Functor f) => Fin n -> LensLikeVL' f (Vec n a) a-ixVL = getIxLens $ N.inlineInduction1 start step where+ixVL :: forall n f a. (N.SNatI n, Functor f) => Fin n -> LensLikeVL' f (Vec n a) a+ixVL = getIxLens $ N.induction1 start step where start :: IxLens f 'Z a start = IxLens F.absurd @@ -76,7 +79,7 @@ ------------------------------------------------------------------------------- -- | An 'L.Iso' from 'toPull' and 'fromPull'.-_Pull :: N.InlineInduction n => L.Iso (Vec n a) (Vec n b) (P.Vec n a) (P.Vec n b)+_Pull :: N.SNatI n => L.Iso (Vec n a) (Vec n b) (P.Vec n a) (P.Vec n b) _Pull = L.iso toPull fromPull -- | Prism from list.@@ -90,5 +93,5 @@ -- >>> review _Vec (True ::: False ::: VNil) -- [True,False] ---_Vec :: N.InlineInduction n => L.Prism' [a] (Vec n a)+_Vec :: N.SNatI n => L.Prism' [a] (Vec n a) _Vec = L.prism' toList fromList
src/Data/Vec/Lazy/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -29,8 +30,11 @@ -- $setup -- >>> :set -XScopedTypeVariables+-- >>> import Data.Fin (Fin (..))+-- >>> import Data.Vec.Lazy -- >>> import Prelude (Maybe (..), Char, Bool (..)) -- >>> import Optics.Core (over, view, set, (%), review, preview)+-- >>> import qualified Data.Type.Nat as N type LensLikeVL f s t a b = (a -> f b) -> s -> f t type LensLikeVL' f s a = LensLikeVL f s s a a@@ -114,6 +118,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex (Fin n) (Vec n) where imap = imap @@ -123,6 +128,7 @@ instance L.TraversableWithIndex (Fin n) (Vec n) where itraverse = itraverse+#endif instance L.Each (Fin n) (Vec n a) (Vec n b) a b where
src/Data/Vec/Pull/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -24,6 +25,8 @@ -- $setup -- >>> :set -XScopedTypeVariables+-- >>> import Data.Fin (Fin (..))+-- >>> import Data.Vec.Pull -- >>> import Optics.Core (over, view, set, (%)) -- >>> import qualified Data.Vec.Lazy as L -- >>> import qualified Data.Vec.Lazy.Optics as L@@ -102,9 +105,11 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex (Fin n) (Vec n) where imap = imap instance N.SNatI n => L.FoldableWithIndex (Fin n) (Vec n) where ifoldMap = ifoldMap ifoldr = ifoldr+#endif
vec-optics.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: vec-optics-version: 0.3+version: 0.4 synopsis: Vec: length-indexed (sized) list: optics support category: Data, Dependent Types, Optics description:@@ -16,10 +16,17 @@ license-file: LICENSE author: Oleg Grenrus <oleg.grenrus@iki.fi> maintainer: Oleg.Grenrus <oleg.grenrus@iki.fi>-copyright: (c) 2017-2019 Oleg Grenrus+copyright: (c) 2017-2021 Oleg Grenrus build-type: Simple extra-source-files: ChangeLog.md-tested-with: GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1+tested-with:+ GHC ==8.0.2+ || ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.4+ || ==8.10.4+ || ==9.0.1 source-repository head type: git@@ -38,15 +45,15 @@ Data.Vec.Pull.Optics -- GHC boot libs- build-depends: base >=4.9 && <4.14+ build-depends: base >=4.9 && <4.16 -- siblings build-depends:- , fin ^>=0.1.1- , vec ^>=0.3+ , fin ^>=0.2+ , vec ^>=0.4 -- other dependencies- build-depends: optics-core ^>=0.2+ build-depends: optics-core >=0.2 && <0.5 other-extensions: CPP FlexibleContexts