on master help sign in
Add examples to cabal file
commit27602de8931eaad8046f1266013f14037ccac99c authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 18 Oct 2017, 11:51 (9 years ago) parent3d17104
4 files changed+145−16
asyncly.cabal+126−3 examples/fastest.hs+1 examples/mergesort.hs+14−13 stack.yaml+4
asyncly.cabal+126−3
@@ -29,6 +29,10 @@ stability: Experimental
2929build-type: Simple
3030cabal-version: >= 1.10
3131
32+source-repository head
33+ type: git
34+ location: https://github.com/harendra-kumar/asyncly
35+
3236flag dev
3337 description: Build development version
3438 manual: True
@@ -39,6 +43,11 @@ flag extra-benchmarks
3943 manual: True
4044 default: False
4145
46+flag examples
47+ description: Build examples
48+ manual: True
49+ default: False
50+
4251library
4352 hs-source-dirs: src
4453 exposed-modules: Asyncly
@@ -144,6 +153,120 @@ benchmark bench
144153 , transient >= 0.4 && < 0.6
145154 default-language: Haskell2010
146155
147−source-repository head
148− type: git
149− location: https://github.com/harendra-kumar/asyncly
156+executable circle-mouse
157+ main-is: circle-mouse.hs
158+ hs-source-dirs: examples
159+ if flag(examples)
160+ buildable: True
161+ build-Depends:
162+ asyncly
163+ , base >= 4.8 && < 5
164+ , SDL >= 0.6.5 && < 0.7
165+ else
166+ buildable: False
167+
168+executable echo-loop
169+ main-is: echo-loop.hs
170+ hs-source-dirs: examples
171+ if flag(examples)
172+ buildable: True
173+ build-Depends:
174+ asyncly
175+ , base >= 4.8 && < 5
176+ else
177+ buildable: False
178+
179+executable fastest
180+ main-is: fastest.hs
181+ hs-source-dirs: examples
182+ if flag(examples)
183+ buildable: True
184+ build-Depends:
185+ asyncly
186+ , base >= 4.8 && < 5
187+ , http-conduit
188+ else
189+ buildable: False
190+
191+executable game
192+ main-is: game.hs
193+ hs-source-dirs: examples
194+ if flag(examples)
195+ buildable: True
196+ build-Depends:
197+ asyncly
198+ , base >= 4.8 && < 5
199+ , mtl >= 2.2 && < 3
200+ else
201+ buildable: False
202+
203+executable listdir
204+ main-is: listdir.hs
205+ hs-source-dirs: examples
206+ if flag(examples)
207+ buildable: True
208+ build-Depends:
209+ asyncly
210+ , base >= 4.8 && < 5
211+ , path
212+ , path-io
213+ else
214+ buildable: False
215+
216+executable loops
217+ main-is: loops.hs
218+ hs-source-dirs: examples
219+ if flag(examples)
220+ buildable: True
221+ build-Depends:
222+ asyncly
223+ , base >= 4.8 && < 5
224+ else
225+ buildable: False
226+
227+executable map-reduce
228+ main-is: map-reduce.hs
229+ hs-source-dirs: examples
230+ if flag(examples)
231+ buildable: True
232+ build-Depends:
233+ asyncly
234+ , base >= 4.8 && < 5
235+ else
236+ buildable: False
237+
238+executable mergesort
239+ main-is: mergesort.hs
240+ hs-source-dirs: examples
241+ if flag(examples)
242+ buildable: True
243+ build-Depends:
244+ asyncly
245+ , base >= 4.8 && < 5
246+ , random
247+ else
248+ buildable: False
249+
250+executable nested-loops
251+ main-is: nested-loops.hs
252+ hs-source-dirs: examples
253+ if flag(examples)
254+ buildable: True
255+ build-Depends:
256+ asyncly
257+ , base >= 4.8 && < 5
258+ , random
259+ else
260+ buildable: False
261+
262+executable parallel-loops
263+ main-is: parallel-loops.hs
264+ hs-source-dirs: examples
265+ if flag(examples)
266+ buildable: True
267+ build-Depends:
268+ asyncly
269+ , base >= 4.8 && < 5
270+ , random
271+ else
272+ buildable: False
examples/fastest.hs+1
@@ -2,6 +2,7 @@
22-- stack runghc
33
44import Asyncly
5+import Asyncly.Prelude (ZipAsync (..))
56import Network.HTTP.Simple
67
78-- Runs three search engine queries in parallel.
examples/mergesort.hs+14−13
@@ -6,33 +6,34 @@
66import Data.Word
77import System.Random
88import Data.List (sort)
9−import qualified Asyncly as A
9+import Asyncly
10+import qualified Asyncly.Prelude as A
1011
1112getSorted = do
12− g <- A.liftIO getStdGen
13+ g <- liftIO getStdGen
1314 let ls = take 100000 (randoms g) :: [Word16]
14− A.foldMapWith (A.<>) return (sort ls)
15+ foldMapWith (<>) return (sort ls)
1516
16−mergeAsync :: (Ord a, A.MonadAsync m)
17− => A.AsyncT m a -> A.AsyncT m a -> A.AsyncT m a
17+mergeAsync :: (Ord a, MonadAsync m)
18+ => AsyncT m a -> AsyncT m a -> AsyncT m a
1819mergeAsync a b = do
19− x <- A.lift $ A.async a
20− y <- A.lift $ A.async b
20+ x <- lift $ async a
21+ y <- lift $ async b
2122 merge x y
2223
2324merge a b = do
24− x <- A.lift $ A.uncons a
25+ x <- lift $ A.uncons a
2526 case x of
2627 Nothing -> b
2728 Just (va, ma) -> do
28− y <- A.lift $ A.uncons b
29+ y <- lift $ A.uncons b
2930 case y of
30− Nothing -> return va A.<> ma
31+ Nothing -> return va <> ma
3132 Just (vb, mb) ->
3233 if (vb < va)
33− then (return vb) A.<> merge (return va A.<> ma) mb
34− else (return va) A.<> merge ma (return vb A.<> mb)
34+ then (return vb) <> merge (return va <> ma) mb
35+ else (return va) <> merge ma (return vb <> mb)
3536
3637main = do
37− xs <- A.toList $ mergeAsync getSorted getSorted
38+ xs <- toList $ mergeAsync getSorted getSorted
3839 putStrLn $ show $ length xs
stack.yaml+4
@@ -5,6 +5,10 @@ packages:
55extra-deps:
66 - lockfree-queue-0.2.3.1
77 - simple-conduit-0.6.0
8+ - SDL-0.6.5.1
89flags: {}
910extra-package-dbs: []
1011rebuild-ghc-options: true
12+# For mac ports installed SDL library on Mac OS X
13+#extra-include-dirs:
14+#- /opt/local/include