Permalink
Browse files

Added (:->) and (:=>) (See issue #61)

  • Loading branch information...
1 parent db5b269 commit 9f829278eee436cea985a389dddc7d7cdd1abcc5 @ekmett committed Sep 25, 2012
Showing with 20 additions and 2 deletions.
  1. +1 −0 CHANGELOG.markdown
  2. +8 −1 src/Control/Lens/Traversal.hs
  3. +11 −1 src/Control/Lens/Type.hs
View
1 CHANGELOG.markdown
@@ -2,6 +2,7 @@
---
* Added `Control.Lens.Zipper`
* Added `<<~`
+* Added `:->` and `:=>` as type operator aliases for `Simple Lens` and `Simple Traversal` respectively
2.9
---
View
9 src/Control/Lens/Traversal.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
+{-# LANGUAGE TypeOperators #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Lens.Traversal
@@ -29,6 +30,7 @@ module Control.Lens.Traversal
(
-- * Lenses
Traversal
+ , (:=>)
-- ** Lensing Traversals
, element
@@ -69,6 +71,8 @@ import Data.Traversable
-- $setup
-- >>> import Control.Lens
+infixr 0 :=>
+
------------------------------------------------------------------------------
-- Traversals
------------------------------------------------------------------------------
@@ -103,6 +107,9 @@ type Traversal a b c d = forall f. Applicative f => (c -> f d) -> a -> f b
-- | @type SimpleTraversal = 'Simple' 'Traversal'@
type SimpleTraversal a b = Traversal a a b b
+-- | This is a commonly-used infix alias for a @'Simple' 'Traversal'@.
+type a :=> b = forall f. Applicative f => (b -> f b) -> a -> f a
+
--------------------------
-- Traversal Combinators
--------------------------
@@ -319,7 +326,7 @@ elementOf l i f a = case getElementOf (l go a) 0 of
-- Attempts to access beyond the range of the 'Traversal' will cause an error.
--
-- @'element' ≡ 'elementOf' 'traverse'@
-element :: Traversable t => Int -> Simple Lens (t a) a
+element :: Traversable t => Int -> t a :-> a
element = elementOf traverse
------------------------------------------------------------------------------
View
12 src/Control/Lens/Type.hs
@@ -5,6 +5,7 @@
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
+{-# LANGUAGE TypeOperators #-}
#ifndef MIN_VERSION_mtl
#define MIN_VERSION_mtl(x,y,z) 1
@@ -56,6 +57,8 @@ module Control.Lens.Type
-- * Lenses
Lens
, Simple
+ , (:->)
+
, lens
, (%%~)
, (%%=)
@@ -100,6 +103,10 @@ import Control.Monad.State.Class as State
-- $setup
-- >>> import Control.Lens
+-- types
+infixr 0 :->
+
+-- terms
infixr 4 %%~
infix 4 %%=
infixr 4 <+~, <*~, <-~, <//~, <^~, <^^~, <**~, <&&~, <||~, <%~, <<%~, <<.~
@@ -163,6 +170,9 @@ type Lens a b c d = forall f. Functor f => (c -> f d) -> a -> f b
-- 'Control.Lens.Setter.Setter', you may have to turn on @LiberalTypeSynonyms@.
type Simple f a b = f a a b b
+-- | This is a commonly used infix alias for a @'Simple' 'Lens'@.
+type a :-> b = forall f. Functor f => (b -> f b) -> a -> f a
+
-- | @type 'SimpleLens' = 'Simple' 'Lens'@
type SimpleLens a b = Lens a a b b
@@ -265,7 +275,7 @@ l %%= f = do
-- | This lens can be used to change the result of a function but only where
-- the arguments match the key given.
-resultAt :: Eq e => e -> Simple Lens (e -> a) a
+resultAt :: Eq e => e -> (e -> a) :-> a
resultAt e afa ea = go <$> afa a where
a = ea e
go a' e' | e == e' = a'

0 comments on commit 9f82927

Please sign in to comment.