Skip to content
This repository
Browse code

shuffling code around

  • Loading branch information...
commit e29a502f94ad80ffc05015856562a09f5deedf90 1 parent 31b4eb8
Edward Kmett authored August 16, 2012
2  CHANGELOG.markdown
Source Rendered
@@ -6,6 +6,8 @@
6 6
 * Renamed `clone` to `cloneLens` in `Control.Lens.Type`
7 7
 * Generalized the type of `zoom` to subsume `focus`.
8 8
 * Removed `Focus(..)` from `Control.Lens.Type`.
  9
+* Factored out `Control.Lens.Isomorphic`.
  10
+* Moved many private types to `Control.Lens.Internal`
9 11
 
10 12
 2.3
11 13
 ---
37  src/Control/Lens/Action.hs
... ...
@@ -1,8 +1,5 @@
1 1
 {-# LANGUAGE Rank2Types #-}
2 2
 {-# LANGUAGE MultiParamTypeClasses #-}
3  
-{-# LANGUAGE FunctionalDependencies #-}
4  
-{-# LANGUAGE FlexibleInstances #-}
5  
-{-# LANGUAGE UndecidableInstances #-}
6 3
 -----------------------------------------------------------------------------
7 4
 -- |
8 5
 -- Module      :  Control.Lens.Action
@@ -28,18 +25,11 @@ module Control.Lens.Action
28 25
 
29 26
   -- * Implementation Details
30 27
   , Acting
31  
-  , Effective(..)
32  
-  , ineffective
33 28
   ) where
34 29
 
35 30
 import Control.Applicative
36  
-import Control.Applicative.Backwards
37 31
 import Control.Lens.Internal
38  
-import Control.Lens.Isomorphic
39  
-import Control.Monad
40 32
 import Control.Monad.Trans.Class
41  
-import Data.Functor.Identity
42  
-import Data.Monoid
43 33
 
44 34
 infixr 8 ^!
45 35
 
@@ -57,31 +47,6 @@ type Action m a c = forall f r. Effective m r f => (c -> f c) -> a -> f a
57 47
 -- You can compose a 'MonadicFold' with another 'MonadicFold' using ('Prelude..') from the @Prelude@.
58 48
 type MonadicFold m a c = forall f r. (Effective m r f, Applicative f) => (c -> f c) -> a -> f a
59 49
 
60  
--- | An 'Effective' 'Functor' ignores its argument and is isomorphic to a monad wrapped around a value.
61  
---
62  
--- That said, the monad is possibly rather unrelated to any 'Applicative' structure.
63  
-class (Monad m, Gettable f) => Effective m r f | f -> m r where
64  
-  effective :: Isomorphic k => k (m r) (f a)
65  
-
66  
--- | A convenient antonym that is used internally.
67  
-ineffective :: Effective m r f => Isomorphic k => k (f a) (m r)
68  
-ineffective = from effective
69  
-{-# INLINE ineffective #-}
70  
-
71  
-instance Effective Identity r (Accessor r) where
72  
-  effective = isomorphic (Accessor . runIdentity) (Identity . runAccessor)
73  
-  {-# INLINE effective #-}
74  
-  {-# SPECIALIZE effective :: Identity r -> Accessor r a #-}
75  
-  {-# SPECIALIZE effective :: Isomorphism (Identity r) (Accessor r a) #-}
76  
-
77  
-instance Effective m r f => Effective m (Dual r) (Backwards f) where
78  
-  effective = isomorphic (Backwards . effective . liftM getDual) (liftM Dual . ineffective . forwards)
79  
-
80  
-instance Monad m => Effective m r (Effect m r) where
81  
-  effective = isomorphic Effect getEffect
82  
-  {-# SPECIALIZE effective :: Monad m => m r -> Effect m r a #-}
83  
-  {-# SPECIALIZE effective :: Monad m => Isomorphism (m r) (Effect m r a) #-}
84  
-
85 50
 -- | Used to evaluate an 'Action'.
86 51
 type Acting m r a c = (c -> Effect m r c) -> a -> Effect m r a
87 52
 
@@ -107,7 +72,7 @@ a ^! l = getEffect (l (Effect . return) a)
107 72
 
108 73
 -- | Construct an 'Action' from a monadic side-effect
109 74
 act :: Monad m => (a -> m c) -> Action m a c
110  
-act amc cfd a = effective (amc a >>= from effective . cfd)
  75
+act amc cfd a = effective (amc a >>= ineffective . cfd)
111 76
 {-# INLINE act #-}
112 77
 
113 78
 -- | A self-running 'Action', analogous to 'Control.Monad.join'.
1  src/Control/Lens/IndexedSetter.hs
@@ -26,7 +26,6 @@ module Control.Lens.IndexedSetter
26 26
 
27 27
 import Control.Lens.Indexed
28 28
 import Control.Lens.Internal
29  
-import Control.Lens.Setter
30 29
 import Control.Lens.Type
31 30
 import Control.Monad.State.Class as State
32 31
 
33  src/Control/Lens/Internal.hs
... ...
@@ -1,5 +1,8 @@
1 1
 {-# LANGUAGE FlexibleContexts #-}
  2
+{-# LANGUAGE FlexibleInstances #-}
2 3
 {-# LANGUAGE UndecidableInstances #-}
  4
+{-# LANGUAGE MultiParamTypeClasses #-}
  5
+{-# LANGUAGE FunctionalDependencies #-}
3 6
 -----------------------------------------------------------------------------
4 7
 -- |
5 8
 -- Module      :  Control.Lens.Internal
@@ -38,7 +41,7 @@ module Control.Lens.Internal
38 41
   , Effect(..)
39 42
   , EffectRWS(..)
40 43
   -- , EffectS(..)
41  
-  , Gettable(..), Accessor(..)
  44
+  , Gettable(..), Accessor(..), Effective(..), ineffective
42 45
   , Settable(..), Mutator(..)
43 46
   ) where
44 47
 
@@ -46,6 +49,7 @@ module Control.Lens.Internal
46 49
 import Control.Applicative
47 50
 import Control.Applicative.Backwards
48 51
 import Control.Category
  52
+import Control.Lens.Isomorphic
49 53
 import Control.Monad
50 54
 import Prelude hiding ((.),id)
51 55
 import Data.Functor.Compose
@@ -360,6 +364,31 @@ instance Monoid r => Applicative (Accessor r) where
360 364
   pure _ = Accessor mempty
361 365
   Accessor a <*> Accessor b = Accessor (mappend a b)
362 366
 
  367
+-- | An 'Effective' 'Functor' ignores its argument and is isomorphic to a monad wrapped around a value.
  368
+--
  369
+-- That said, the monad is possibly rather unrelated to any 'Applicative' structure.
  370
+class (Monad m, Gettable f) => Effective m r f | f -> m r where
  371
+  effective :: Isomorphic k => k (m r) (f a)
  372
+
  373
+-- | A convenient antonym that is used internally.
  374
+ineffective :: Effective m r f => Isomorphic k => k (f a) (m r)
  375
+ineffective = from effective
  376
+{-# INLINE ineffective #-}
  377
+
  378
+instance Effective Identity r (Accessor r) where
  379
+  effective = isomorphic (Accessor . runIdentity) (Identity . runAccessor)
  380
+  {-# INLINE effective #-}
  381
+  {-# SPECIALIZE effective :: Identity r -> Accessor r a #-}
  382
+  {-# SPECIALIZE effective :: Isomorphism (Identity r) (Accessor r a) #-}
  383
+
  384
+instance Effective m r f => Effective m (Dual r) (Backwards f) where
  385
+  effective = isomorphic (Backwards . effective . liftM getDual) (liftM Dual . ineffective . forwards)
  386
+
  387
+instance Monad m => Effective m r (Effect m r) where
  388
+  effective = isomorphic Effect getEffect
  389
+  {-# SPECIALIZE effective :: Monad m => m r -> Effect m r a #-}
  390
+  {-# SPECIALIZE effective :: Monad m => Isomorphism (m r) (Effect m r a) #-}
  391
+
363 392
 -----------------------------------------------------------------------------
364 393
 -- Settables & Mutators
365 394
 -----------------------------------------------------------------------------
@@ -398,3 +427,5 @@ instance Functor Mutator where
398 427
 instance Applicative Mutator where
399 428
   pure = Mutator
400 429
   Mutator f <*> Mutator a = Mutator (f a)
  430
+
  431
+
3  src/Control/Lens/Setter.hs
@@ -47,11 +47,8 @@ module Control.Lens.Setter
47 47
   ) where
48 48
 
49 49
 import Control.Applicative
50  
-import Control.Applicative.Backwards
51 50
 import Control.Lens.Internal
52 51
 import Control.Monad.State.Class        as State
53  
-import Data.Functor.Compose
54  
-import Data.Functor.Identity
55 52
 
56 53
 infixr 4 .~, +~, *~, -~, //~, ^~, ^^~, **~, &&~, ||~, %~, <.~
57 54
 infix  4 .=, +=, *=, -=, //=, ^=, ^^=, **=, &&=, ||=, %=, <.=
4  src/Control/Lens/Zoom.hs
@@ -6,10 +6,6 @@
6 6
 {-# LANGUAGE FlexibleInstances #-}
7 7
 {-# LANGUAGE UndecidableInstances #-}
8 8
 
9  
-#ifndef MIN_VERSION_mtl
10  
-#define MIN_VERSION_mtl(x,y,z) 1
11  
-#endif
12  
-
13 9
 -------------------------------------------------------------------------------
14 10
 -- |
15 11
 -- Module      :  Control.Lens.Zoom

0 notes on commit e29a502

Please sign in to comment.
Something went wrong with that request. Please try again.