Aleksey Khudyakov avatar Aleksey Khudyakov committed 2f569c6

Change definition of Index type class in order to allow
lens implementation

Comments (0)

Files changed (1)

Data/Vector/Fixed/Cont.hs

   , any
   ) where
 
-import Control.Applicative (Applicative(..))
+import Control.Applicative (Applicative(..),(<$>))
 import Data.Complex        (Complex(..))
 import Data.Vector.Fixed.Internal.Arity
 import Data.Vector.Fixed.Internal.Id
 -- | Type class for indexing of vector when index value is known at
 --   compile time.
 class Index k n where
-  getF :: k -> Fun n a a
-  putF :: k -> a -> Fun n a a -> Fun n a a
+  getF  :: k -> Fun n a a
+  lensF :: Functor f => k -> (a -> f a) -> Fun n a r -> Fun n a (f r)
 
 instance Arity n => Index Z (S n) where
-  getF _           = Fun $ \(a :: a) -> unFun (pure a :: Fun n a a)
-  putF _ x (Fun f) = Fun $ \_ -> f x
+  getF  _       = Fun $ \(a :: a) -> unFun (pure a :: Fun n a a)
+  lensF _ f fun = Fun $ \(a :: a) -> unFun $
+    (\g -> g <$> f a) <$> shuffleFun (apFun fun)
+  {-# INLINE getF  #-}
+  {-# INLINE lensF #-}
 
 instance Index k n => Index (S k) (S n) where
-  getF _           = Fun $ \(_::a) -> unFun (getF (undefined :: k) :: Fun n a a)
-  putF _ x (Fun f) = Fun $ \(a::a) -> unFun $ putF (undefined :: k) x (Fun (f a) :: Fun n a a)
+  getF  _       = Fun $ \(_::a) -> unFun (getF  (undefined :: k) :: Fun n a a)
+  lensF _ f fun = Fun $ \a      -> unFun (lensF (undefined :: k) f (apFun fun a))
+  {-# INLINE getF  #-}
+  {-# INLINE lensF #-}
 
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.