on master help sign in
Remove unnecessary proxy passing
commit17d4165709cc3b7c04e88d104d9b69bf36674928 authorIndex Int <vlad.z.4096@gmail.com> dateWed 27 Jan 2016, 14:20 (11 years ago) parent6f616b3
5 files changed+39−69
src/Control/Monad/Trans/Ether/Except.hs+5−11 src/Control/Monad/Trans/Ether/Reader.hs+6−12 src/Control/Monad/Trans/Ether/State/Lazy.hs+10−16 src/Control/Monad/Trans/Ether/State/Strict.hs+10−16 src/Control/Monad/Trans/Ether/Writer.hs+8−14
src/Control/Monad/Trans/Ether/Except.hs+5−11
@@ -39,7 +39,7 @@ type Except tag e = ExceptT tag e Identity
3939
4040-- | Runs an 'Except' and returns either an exception or a normal value.
4141runExcept :: proxy tag -> Except tag e a -> Either e a
42−runExcept t = Trans.runExcept . untagged t
42+runExcept _ = Trans.runExcept . unpack
4343
4444-- | The exception monad transformer.
4545--
@@ -47,15 +47,9 @@ runExcept t = Trans.runExcept . untagged t
4747-- the first exception.
4848type ExceptT tag e = TT tag (Trans.ExceptT e)
4949
50−tagged :: proxy tag -> Trans.ExceptT e m a -> ExceptT tag e m a
51−tagged _ = pack
52−
53−untagged :: proxy tag -> ExceptT tag e m a -> Trans.ExceptT e m a
54−untagged _ = unpack
55−
5650-- | Constructor for computations in the exception monad transformer.
5751exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a
58−exceptT t = tagged t . Trans.ExceptT
52+exceptT _ = pack . Trans.ExceptT
5953
6054-- | Constructor for computations in the exception monad
6155-- (the inverse of 'runExcept').
@@ -64,12 +58,12 @@ except t = exceptT t . return
6458
6559-- | Runs an 'ExceptT' and returns either an exception or a normal value.
6660runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a)
67−runExceptT t = Trans.runExceptT . untagged t
61+runExceptT _ = Trans.runExceptT . unpack
6862
6963-- | Is used within a monadic computation to begin exception processing.
7064throw :: Monad m => proxy tag -> e -> ExceptT tag e m a
71−throw t = tagged t . Trans.throwE
65+throw _ = pack . Trans.throwE
7266
7367-- | A handler function to handle previous exceptions and return to normal execution.
7468catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
75−catch t m h = tagged t $ Trans.catchE (untagged t m) (untagged t . h)
69+catch _ m h = pack $ Trans.catchE (unpack m) (unpack . h)
src/Control/Monad/Trans/Ether/Reader.hs+6−12
@@ -43,34 +43,28 @@ type Reader tag r = ReaderT tag r Identity
4343-- the inherited environment to both subcomputations.
4444type ReaderT tag r = TT tag (Trans.ReaderT r)
4545
46−tagged :: proxy tag -> Trans.ReaderT r m a -> ReaderT tag r m a
47−tagged _ = pack
48−
49−untagged :: proxy tag -> ReaderT tag r m a -> Trans.ReaderT r m a
50−untagged _ = unpack
51−
5246-- | Constructor for computations in the reader monad transformer.
5347readerT :: proxy tag -> (r -> m a) -> ReaderT tag r m a
54−readerT t = tagged t . Trans.ReaderT
48+readerT _ = pack . Trans.ReaderT
5549
5650-- | Constructor for computations in the reader monad
5751-- (the inverse of 'runReader').
5852reader :: Monad m => proxy tag -> (r -> a) -> ReaderT tag r m a
59−reader t = tagged t . Trans.reader
53+reader _ = pack . Trans.reader
6054
6155-- | Runs a 'ReaderT' with the given environment
6256-- and returns the vinal value.
6357runReaderT :: proxy tag -> ReaderT tag r m a -> r -> m a
64−runReaderT t = Trans.runReaderT . untagged t
58+runReaderT _ = Trans.runReaderT . unpack
6559
6660-- | Runs a 'ReaderT' with the given environment
6761-- and returns the vinal value.
6862runReader :: proxy tag -> Reader tag r a -> r -> a
69−runReader t = Trans.runReader . untagged t
63+runReader _ = Trans.runReader . unpack
7064
7165-- | Fetch the value of the environment.
7266ask :: Monad m => proxy tag -> ReaderT tag r m r
73−ask t = tagged t Trans.ask
67+ask _ = pack Trans.ask
7468
7569-- | Execute a computation in a modified environment
7670-- (a specialization of 'withReaderT').
@@ -83,4 +77,4 @@ local
8377 -> ReaderT tag r m a
8478 -- ^ Computation to run in the modified environment.
8579 -> ReaderT tag r m a
86−local t f m = tagged t $ Trans.withReaderT f (untagged t m)
80+local _ f = pack . Trans.withReaderT f . unpack
src/Control/Monad/Trans/Ether/State/Lazy.hs+10−16
@@ -46,55 +46,49 @@ type State tag r = StateT tag r Identity
4646-- the final state of the first computation as the initial state of the second.
4747type StateT tag s = TT tag (Trans.StateT s)
4848
49−tagged :: proxy tag -> Trans.StateT s m a -> StateT tag s m a
50−tagged _ = pack
51−
52−untagged :: proxy tag -> StateT tag s m a -> Trans.StateT s m a
53−untagged _ = unpack
54−
5549-- | Constructor for computations in the state monad transformer.
5650stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a
57−stateT t = tagged t . Trans.StateT
51+stateT _ = pack . Trans.StateT
5852
5953-- | Constructor for computations in the state monad
6054-- (the inverse of 'runState').
6155state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a
62−state t = tagged t . Trans.state
56+state _ = pack . Trans.state
6357
6458-- | Runs a 'StateT' with the given initial state
6559-- and returns both the final value and the final state.
6660runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s)
67−runStateT t = Trans.runStateT . untagged t
61+runStateT _ = Trans.runStateT . unpack
6862
6963-- | Runs a 'StateT' with the given initial state
7064-- and returns the final value, discarding the final state.
7165evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a
72−evalStateT t = Trans.evalStateT . untagged t
66+evalStateT _ = Trans.evalStateT . unpack
7367
7468-- | Runs a 'StateT' with the given initial state
7569-- and returns the final state, discarding the final value.
7670execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s
77−execStateT t = Trans.execStateT . untagged t
71+execStateT _ = Trans.execStateT . unpack
7872
7973-- | Runs a 'State' with the given initial state
8074-- and returns both the final value and the final state.
8175runState :: proxy tag -> State tag s a -> s -> (a, s)
82−runState t = Trans.runState . untagged t
76+runState _ = Trans.runState . unpack
8377
8478-- | Runs a 'State' with the given initial state
8579-- and returns the final value, discarding the final state.
8680evalState :: proxy tag -> State tag s a -> s -> a
87−evalState t = Trans.evalState . untagged t
81+evalState _ = Trans.evalState . unpack
8882
8983-- | Runs a 'State' with the given initial state
9084-- and returns the final state, discarding the final value.
9185execState :: proxy tag -> State tag s a -> s -> s
92−execState t = Trans.execState . untagged t
86+execState _ = Trans.execState . unpack
9387
9488-- | Fetch the current value of the state within the monad.
9589get :: Monad m => proxy tag -> StateT tag s m s
96−get t = tagged t Trans.get
90+get _ = pack Trans.get
9791
9892-- | Set the value of the state within the monad.
9993put :: Monad m => proxy tag -> s -> StateT tag s m ()
100−put t = tagged t . Trans.put
94+put _ = pack . Trans.put
src/Control/Monad/Trans/Ether/State/Strict.hs+10−16
@@ -46,55 +46,49 @@ type State tag r = StateT tag r Identity
4646-- the final state of the first computation as the initial state of the second.
4747type StateT tag s = TT tag (Trans.StateT s)
4848
49−tagged :: proxy tag -> Trans.StateT s m a -> StateT tag s m a
50−tagged _ = pack
51−
52−untagged :: proxy tag -> StateT tag s m a -> Trans.StateT s m a
53−untagged _ = unpack
54−
5549-- | Constructor for computations in the state monad transformer.
5650stateT :: proxy tag -> (s -> m (a, s)) -> StateT tag s m a
57−stateT t = tagged t . Trans.StateT
51+stateT _ = pack . Trans.StateT
5852
5953-- | Constructor for computations in the state monad
6054-- (the inverse of 'runState').
6155state :: Monad m => proxy tag -> (s -> (a, s)) -> StateT tag s m a
62−state t = tagged t . Trans.state
56+state _ = pack . Trans.state
6357
6458-- | Runs a 'StateT' with the given initial state
6559-- and returns both the final value and the final state.
6660runStateT :: proxy tag -> StateT tag s m a -> s -> m (a, s)
67−runStateT t = Trans.runStateT . untagged t
61+runStateT _ = Trans.runStateT . unpack
6862
6963-- | Runs a 'StateT' with the given initial state
7064-- and returns the final value, discarding the final state.
7165evalStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m a
72−evalStateT t = Trans.evalStateT . untagged t
66+evalStateT _ = Trans.evalStateT . unpack
7367
7468-- | Runs a 'StateT' with the given initial state
7569-- and returns the final state, discarding the final value.
7670execStateT :: Monad m => proxy tag -> StateT tag s m a -> s -> m s
77−execStateT t = Trans.execStateT . untagged t
71+execStateT _ = Trans.execStateT . unpack
7872
7973-- | Runs a 'State' with the given initial state
8074-- and returns both the final value and the final state.
8175runState :: proxy tag -> State tag s a -> s -> (a, s)
82−runState t = Trans.runState . untagged t
76+runState _ = Trans.runState . unpack
8377
8478-- | Runs a 'State' with the given initial state
8579-- and returns the final value, discarding the final state.
8680evalState :: proxy tag -> State tag s a -> s -> a
87−evalState t = Trans.evalState . untagged t
81+evalState _ = Trans.evalState . unpack
8882
8983-- | Runs a 'State' with the given initial state
9084-- and returns the final state, discarding the final value.
9185execState :: proxy tag -> State tag s a -> s -> s
92−execState t = Trans.execState . untagged t
86+execState _ = Trans.execState . unpack
9387
9488-- | Fetch the current value of the state within the monad.
9589get :: Monad m => proxy tag -> StateT tag s m s
96−get t = tagged t Trans.get
90+get _ = pack Trans.get
9791
9892-- | Set the value of the state within the monad.
9993put :: Monad m => proxy tag -> s -> StateT tag s m ()
100−put t = tagged t . Trans.put
94+put _ = pack . Trans.put
src/Control/Monad/Trans/Ether/Writer.hs+8−14
@@ -50,40 +50,34 @@ type Writer tag w = WriterT tag w Identity
5050-- the outputs of the subcomputations using 'mappend'.
5151type WriterT tag w = TT tag (Trans.WriterT w)
5252
53−tagged :: proxy tag -> Trans.WriterT w m a -> WriterT tag w m a
54−tagged _ = pack
55−
56−untagged :: proxy tag -> WriterT tag w m a -> Trans.WriterT w m a
57−untagged _ = unpack
58−
5953-- | Constructor for computations in the writer monad transformer.
6054writerT :: proxy tag -> m (a, w) -> WriterT tag w m a
61−writerT t = tagged t . Trans.WriterT
55+writerT _ = pack . Trans.WriterT
6256
6357-- | Constructor for computations in the writer monad
6458-- (the inverse of 'runWriter').
6559writer :: Monad m => proxy tag -> (a, w) -> WriterT tag w m a
66−writer t = tagged t . Trans.writer
60+writer _ = pack . Trans.writer
6761
6862-- | Runs a 'WriterT' and returns both the normal value
6963-- and the final accumulator.
7064runWriterT :: proxy tag -> WriterT tag w m a -> m (a, w)
71−runWriterT t = Trans.runWriterT . untagged t
65+runWriterT _ = Trans.runWriterT . unpack
7266
7367-- | Runs a 'Writer' and returns both the normal value
7468-- and the final accumulator.
7569runWriter :: proxy tag -> Writer tag w a -> (a, w)
76−runWriter t = Trans.runWriter . untagged t
70+runWriter _ = Trans.runWriter . unpack
7771
7872-- | Runs a 'WriterT' and returns the final accumulator,
7973-- discarding the normal value.
8074execWriterT :: Monad m => proxy tag -> WriterT tag w m a -> m w
81−execWriterT t = Trans.execWriterT . untagged t
75+execWriterT _ = Trans.execWriterT . unpack
8276
8377-- | Runs a 'Writer' and returns the final accumulator,
8478-- discarding the normal value.
8579execWriter :: proxy tag -> Writer tag w a -> w
86−execWriter t = Trans.execWriter . untagged t
80+execWriter _ = Trans.execWriter . unpack
8781
8882-- | Appends a value to the accumulator within the monad.
8983tell :: Monad m => proxy tag -> w -> WriterT tag w m ()
@@ -91,9 +85,9 @@ tell t w = writer t ((), w)
9185
9286-- | Executes an action and adds its accumulator to the value of the computation.
9387listen :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m a -> WriterT tag w m (a, w)
94−listen t m = tagged t $ Trans.listen (untagged t m)
88+listen _ = pack . Trans.listen . unpack
9589
9690-- | Executes an action which returns a value and a function, and returns the
9791-- value, applying the function to the accumulator.
9892pass :: (Monoid w, Monad m) => proxy tag -> WriterT tag w m (a, w -> w) -> WriterT tag w m a
99−pass t m = tagged t $ Trans.pass (untagged t m)
93+pass _ = pack . Trans.pass . unpack