on master help sign in
Upgrade warning options to 8.2.1 and add more options
9c80d6cHarendra Kumar
asyncly.cabal+39−8
@@ -35,8 +35,18 @@ library
35 , Asyncly.AsyncT
35 , Asyncly.AsyncT
36
36
37 default-language: Haskell2010
37 default-language: Haskell2010
38− ghc-options: -Wall -fwarn-identities -fwarn-incomplete-record-updates
38+ ghc-options: -Wall
39− -fwarn-incomplete-uni-patterns -fwarn-tabs
39+ -Wcompat
40+ -Wunrecognised-warning-flags
41+ -Widentities
42+ -Wincomplete-record-updates
43+ -Wincomplete-uni-patterns
44+ -Wredundant-constraints
45+ -Wmissing-exported-signatures
46+ -Wnoncanonical-monad-instances
47+ -Wnoncanonical-monadfail-instances
48+ -Wmissed-specialisations
49+ -Wall-missed-specialisations
40
50
41 build-depends: base >= 4.8 && < 5
51 build-depends: base >= 4.8 && < 5
42 , atomic-primops >= 0.8 && < 0.9
52 , atomic-primops >= 0.8 && < 0.9
@@ -57,8 +67,19 @@ test-suite test
57 type: exitcode-stdio-1.0
67 type: exitcode-stdio-1.0
58 main-is: Main.hs
68 main-is: Main.hs
59 hs-source-dirs: test
69 hs-source-dirs: test
60− ghc-options: -O0 -Wall -fwarn-identities -fwarn-incomplete-record-updates
70+ ghc-options: -O0
61− -fwarn-incomplete-uni-patterns -fwarn-tabs
71+ -Wall
72+ -Wcompat
73+ -Wunrecognised-warning-flags
74+ -Widentities
75+ -Wincomplete-record-updates
76+ -Wincomplete-uni-patterns
77+ -Wredundant-constraints
78+ -Wmissing-exported-signatures
79+ -Wnoncanonical-monad-instances
80+ -Wnoncanonical-monadfail-instances
81+ -Wmissed-specialisations
82+ -Wall-missed-specialisations
62 build-depends:
83 build-depends:
63 asyncly
84 asyncly
64 , base >= 4.8 && < 5
85 , base >= 4.8 && < 5
@@ -78,10 +99,20 @@ benchmark bench
78 type: exitcode-stdio-1.0
99 type: exitcode-stdio-1.0
79 main-is: Main.hs
100 main-is: Main.hs
80 hs-source-dirs: benchmark
101 hs-source-dirs: benchmark
81− ghc-options: -Wall -fwarn-identities -fwarn-incomplete-record-updates
102+ ghc-options: -O2
82− -fwarn-incomplete-uni-patterns -fwarn-tabs
103+ -Wall
83− -O2 -funbox-strict-fields
104+ -Wcompat
105+ -Wunrecognised-warning-flags
106+ -Widentities
107+ -Wincomplete-record-updates
108+ -Wincomplete-uni-patterns
109+ -Wredundant-constraints
110+ -Wmissing-exported-signatures
111+ -Wnoncanonical-monad-instances
112+ -Wnoncanonical-monadfail-instances
113+ -Wmissed-specialisations
114+ -Wall-missed-specialisations
84− -fno-ignore-asserts
115+ -fno-ignore-asserts
85 build-depends:
116 build-depends:
86 asyncly
117 asyncly
87 , atomic-primops >= 0.8 && < 0.9
118 , atomic-primops >= 0.8 && < 0.9
src/Asyncly/AsyncT.hs+30−26
@@ -120,7 +120,7 @@ newtype AsyncT m a =
120type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
120type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
121
121
122------------------------------------------------------------------------------
122------------------------------------------------------------------------------
123−-- Monad
123+-- Monoid
124------------------------------------------------------------------------------
124------------------------------------------------------------------------------
125
125
126-- | Appends the results of two AsyncT computations in order.
126-- | Appends the results of two AsyncT computations in order.
@@ -151,6 +151,32 @@ infixr 5 <=>
151(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
151(<=>) :: AsyncT m a -> AsyncT m a -> AsyncT m a
152(<=>) = interleave
152(<=>) = interleave
153
153
154+------------------------------------------------------------------------------
155+-- Functor
156+------------------------------------------------------------------------------
157+
158+instance Monad m => Functor (AsyncT m) where
159+ fmap = liftM
160+
161+------------------------------------------------------------------------------
162+-- Applicative
163+------------------------------------------------------------------------------
164+
165+-- Note: We cannot have the applicative instance run the two actions in
166+-- parallel. This is because the first action can always return empty and in
167+-- case it returns empty we should not be starting the second action. Therefore
168+-- we can only start the second action after getting a result from the first.
169+-- For running applicative actions in parallel we can use the async package and
170+-- lift the result into AsyncT.
171+
172+instance Monad m => Applicative (AsyncT m) where
173+ pure a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
174+ (<*>) = ap
175+
176+------------------------------------------------------------------------------
177+-- Monad
178+------------------------------------------------------------------------------
179+
154-- We do not use bind for parallelism. That is, we do not start each iteration
180-- We do not use bind for parallelism. That is, we do not start each iteration
155-- of the list in parallel. That will introduce too much uncontrolled
181-- of the list in parallel. That will introduce too much uncontrolled
156-- parallelism. Instead we control parallelism using <|>, it is used for
182-- parallelism. Instead we control parallelism using <|>, it is used for
@@ -184,7 +210,7 @@ bindWith k m f = go m
184 in g Nothing stp yield
210 in g Nothing stp yield
185
211
186instance Monad m => Monad (AsyncT m) where
212instance Monad m => Monad (AsyncT m) where
187− return a = AsyncT $ \ctx _ yld -> yld a ctx Nothing
213+ return = pure
188
214
189 AsyncT m >>= f = AsyncT $ \_ stp yld ->
215 AsyncT m >>= f = AsyncT $ \_ stp yld ->
190 let run x = (runAsyncT x) Nothing stp yld
216 let run x = (runAsyncT x) Nothing stp yld
@@ -204,28 +230,6 @@ instance Monad m => Monad (AsyncT m) where
204(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
230(>|>) :: MonadAsync m => AsyncT m a -> (a -> AsyncT m b) -> AsyncT m b
205(>|>) = bindWith (<|>)
231(>|>) = bindWith (<|>)
206
232
207−------------------------------------------------------------------------------
208−-- Functor
209−------------------------------------------------------------------------------
210−
211−instance Monad m => Functor (AsyncT m) where
212− fmap = liftM
213−
214−------------------------------------------------------------------------------
215−-- Applicative
216−------------------------------------------------------------------------------
217−
218−-- Note: We cannot have the applicative instance run the two actions in
219−-- parallel. This is because the first action can always return empty and in
220−-- case it returns empty we should not be starting the second action. Therefore
221−-- we can only start the second action after getting a result from the first.
222−-- For running applicative actions in parallel we can use the async package and
223−-- lift the result into AsyncT.
224−
225−instance Monad m => Applicative (AsyncT m) where
226− pure = return
227− (<*>) = ap
228−
229------------------------------------------------------------------------------
233------------------------------------------------------------------------------
230-- Alternative
234-- Alternative
231------------------------------------------------------------------------------
235------------------------------------------------------------------------------
@@ -478,10 +482,10 @@ instance MonadAsync m => Alternative (AsyncT m) where
478-- | Just like '<>' except that it can execute the action on the right in
482-- | Just like '<>' except that it can execute the action on the right in
479-- parallel ahead of time. Returns the results in serial order like '<>' from
483-- parallel ahead of time. Returns the results in serial order like '<>' from
480-- left to right.
484-- left to right.
481−parAhead :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
485+parAhead :: AsyncT m a -> AsyncT m a -> AsyncT m a
482parAhead = undefined
486parAhead = undefined
483
487
484−(<>|) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
488+(<>|) :: AsyncT m a -> AsyncT m a -> AsyncT m a
485(<>|) = parAhead
489(<>|) = parAhead
486
490
487-- | Left biased parallel execution. Actions may run in parallel but not
491-- | Left biased parallel execution. Actions may run in parallel but not