packages feed

ral-optics 0.1 → 0.2

raw patch · 8 files changed

+110/−7 lines, 8 filesdep ~basedep ~findep ~optics-core

Dependency ranges changed: base, fin, optics-core, ral

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Version history for ral +## 0.2++- Support `fin-0.2`+ ## 0.1  - First version. Released on an unsuspecting world.
ral-optics.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.2 name:               ral-optics-version:            0.1+version:            0.2 synopsis:           Length-indexed random access lists: optics utilities. category:           Data, Dependent Types, Singletons, Optics description:@@ -13,10 +13,17 @@ license-file:       LICENSE author:             Oleg Grenrus <oleg.grenrus@iki.fi> maintainer:         Oleg.Grenrus <oleg.grenrus@iki.fi>-copyright:          (c) 2019 Oleg Grenrus+copyright:          (c) 2019-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@@ -32,6 +39,7 @@     Data.RAList.Optics     Data.RAVec.NonEmpty.Optics     Data.RAVec.Optics+    Data.RAVec.Tree.DF.Optics     Data.RAVec.Tree.Optics    other-modules:@@ -39,11 +47,11 @@     Data.RAVec.NonEmpty.Optics.Internal    build-depends:-    , base         >=4.9   && <4.14+    , base         >=4.9 && <4.16     , bin          ^>=0.1-    , fin          ^>=0.1.1-    , optics-core  ^>=0.2-    , ral          ^>=0.1+    , fin          ^>=0.2+    , optics-core  >=0.2 && <0.5+    , ral          ^>=0.2  -- dump-core -- if impl(ghc >= 8.0)
src/Data/RAList/NonEmpty/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes            #-}@@ -27,6 +28,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex Int NERAList where     imap = imap @@ -35,6 +37,7 @@  instance L.TraversableWithIndex Int NERAList where     itraverse = itraverse+#endif  instance L.Each Int (NERAList a) (NERAList b) a b 
src/Data/RAList/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes            #-}@@ -30,6 +31,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex Int RAList where     imap = imap @@ -38,6 +40,7 @@  instance L.TraversableWithIndex Int RAList where     itraverse = itraverse+#endif  instance L.Each Int (RAList a) (RAList b) a b 
src/Data/RAVec/NonEmpty/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies          #-}@@ -34,6 +35,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex (PosP b) (NERAVec b) where     imap = imap @@ -53,6 +55,7 @@  instance L.TraversableWithIndex (PosP' n b) (NERAVec' n b) where     itraverse = itraverse'+#endif  instance L.Each (PosP n) (NERAVec n a) (NERAVec n b) a b where 
src/Data/RAVec/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies          #-}@@ -10,6 +11,7 @@ import Control.Applicative        ((<$>)) import Data.Bin.Pos               (Pos (..)) import Data.RAVec.NonEmpty.Optics ()+import Prelude                    (Functor)  import qualified Data.RAVec.NonEmpty.Optics.Internal as NE import qualified Optics.Core                         as L@@ -20,6 +22,7 @@ -- >>> import Optics.Core (set) -- >>> import Prelude -- >>> import qualified Data.Type.Bin as B+-- >>> import Data.RAVec  ------------------------------------------------------------------------------- -- Indexing@@ -40,6 +43,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex (Pos b) (RAVec b) where     imap = imap @@ -49,6 +53,7 @@  instance L.TraversableWithIndex (Pos b) (RAVec b) where     itraverse = itraverse+#endif  instance L.Each (Pos n) (RAVec n a) (RAVec n b) a b where 
+ src/Data/RAVec/Tree/DF/Optics.hs view
@@ -0,0 +1,72 @@+{-# LANGUAGE CPP                   #-}+{-# LANGUAGE FlexibleInstances     #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE RankNTypes            #-}+{-# LANGUAGE TypeFamilies          #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Data.RAVec.Tree.DF.Optics (+    -- * Indexing+    ix,+    ) where++import Control.Applicative ((<$>))+import Data.Wrd            (Wrd (..))+import Prelude             (Functor)++import qualified Data.Type.Nat as N+import qualified Optics.Core   as L++import Data.RAVec.Tree.DF++-- $setup+-- >>> import Optics.Core (set, (&), (.~))+-- >>> import Prelude+-- >>> import Data.RAVec.Tree.DF+-- >>> import Data.Wrd (Wrd (..))++type LensLikeVL f s t a b = (a -> f b) -> s -> f t+type LensLikeVL' f s a = LensLikeVL f s s a a++-------------------------------------------------------------------------------+-- Indexing+-------------------------------------------------------------------------------++-- | Index lens.+--+-- >>> let tree = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))+-- >>> tree & ix (W1 $ W0 WE) .~ 'z'+-- Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'z') (Leaf 'd'))+--+ix :: Wrd n -> L.Lens' (Tree n a) a+ix i = L.lensVL (ixVL i)++ixVL :: Functor f => Wrd n -> LensLikeVL' f (Tree n a) a+ixVL WE      f (Leaf x)   = Leaf <$> f x+ixVL (W0 is) f (Node x y) = (`Node` y) <$> ixVL is f x+ixVL (W1 is) f (Node x y) = (x `Node`) <$> ixVL is f y++-------------------------------------------------------------------------------+-- Instances+-------------------------------------------------------------------------------++#if !MIN_VERSION_optics_core(0,4,0)+instance N.SNatI n => L.FunctorWithIndex (Wrd n) (Tree n) where+    imap = imap++instance N.SNatI n => L.FoldableWithIndex (Wrd n) (Tree n) where+    ifoldMap = ifoldMap+    ifoldr   = ifoldr++instance N.SNatI n => L.TraversableWithIndex (Wrd n) (Tree n) where+    itraverse = itraverse+#endif++instance N.SNatI n => L.Each (Wrd n) (Tree n a) (Tree n b) a b++type instance L.Index (Tree n a)   = Wrd n+type instance L.IxValue (Tree n a) = a++instance L.Ixed (Tree n a) where+    type IxKind (Tree n a) = L.A_Lens+    ix = ix+
src/Data/RAVec/Tree/Optics.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies          #-}@@ -18,6 +19,8 @@ -- $setup -- >>> import Optics.Core (set) -- >>> import Prelude+-- >>> import Data.RAVec.Tree+-- >>> import Data.Wrd (Wrd (..))  type LensLikeVL f s t a b = (a -> f b) -> s -> f t type LensLikeVL' f s a = LensLikeVL f s s a a@@ -44,6 +47,7 @@ -- Instances ------------------------------------------------------------------------------- +#if !MIN_VERSION_optics_core(0,4,0) instance L.FunctorWithIndex (Wrd n) (Tree n) where     imap = imap @@ -53,6 +57,7 @@  instance L.TraversableWithIndex (Wrd n) (Tree n) where     itraverse = itraverse+#endif  instance L.Each (Wrd n) (Tree n a) (Tree n b) a b where