Permalink
Browse files

import isomorphism library from groupoids.

  • Loading branch information...
1 parent 3af3d68 commit 5d2644270d6bb5842c5c5c67570ab6aac53de228 @roconnor committed Jun 9, 2012
Showing with 5 additions and 3 deletions.
  1. +1 −0 data-lens.cabal
  2. +4 −3 src/Data/Lens/Common.hs
View
@@ -29,6 +29,7 @@ library
comonad-transformers >= 2.0 && < 2.2,
containers >= 0.3 && < 0.5,
semigroupoids >= 1.2.4 && < 1.4,
+ groupoids >= 0.2 && < 0.3,
transformers >= 0.2.0 && < 0.4
if flag(DeriveDataTypeable)
@@ -2,7 +2,7 @@ module Data.Lens.Common
( Lens(..)
-- * Lens construction
, lens -- build a lens from a getter and setter
- , iso -- build a lens from an isomorphism
+ , isoL -- build a lens from an isomorphism
-- * Functional API
, getL
, setL
@@ -36,6 +36,7 @@ import Control.Category.Product
import Data.Functor.Identity
import Data.Functor.Apply
import Data.Semigroupoid
+import Data.Isomorphism
import Prelude hiding ((.), id)
import Data.IntMap (IntMap)
import qualified Data.Map as Map
@@ -66,8 +67,8 @@ lens :: (a -> b) -> (b -> a -> a) -> Lens a b
lens get set = Lens $ \a -> store (`set` a) (get a)
-- | build a lens out of an isomorphism
-iso :: (a -> b) -> (b -> a) -> Lens a b
-iso f g = Lens (store g . f)
+isoL :: Iso (->) a b -> Lens a b
+isoL f = Lens (store (project f) . (embed f))
-- | Gets the getter function from a lens.
getL :: Lens a b -> a -> b

0 comments on commit 5d26442

Please sign in to comment.