on master help sign in
Add Examples module, make SDL examples optional
2ed8b60Harendra Kumar
src/Streamly/Examples.hsnew file+60
@@ -0,0 +1,60 @@
1+{-# LANGUAGE CPP #-}
2+-- |
3+-- Module : Streamly.Examples
4+-- Copyright : (c) 2017 Harendra Kumar
5+--
6+-- License : BSD3
7+-- Maintainer : harendra.kumar@gmail.com
8+-- Stability : experimental
9+-- Portability : GHC
10+--
11+-- To run these examples:
12+--
13+-- You need to build the library with the "examples" flag on e.g.
14+-- @stack build --flag streamly:examples@. To include the SDL examples as well
15+-- use @stack build --flag streamly:examples-sdl@. You will have to make sure
16+-- that you have the SDL OS package installed on your system and the headers
17+-- are visible to Haskell build tool.
18+--
19+-- You can directly evaluate the respective file and its main function using
20+-- ghc, like this (this may not work when built with @examples-sdl@ flag):
21+--
22+-- @
23+-- \$ stack ghc -- -e acidRainGame src\/Streamly\/Examples\/AcidRainGame.hs
24+-- @
25+--
26+-- Alternatively, you can create a file calling the main function and compile
27+-- it:
28+--
29+-- @
30+-- \$ cat ex.hs
31+-- import Streamly.Examples
32+-- main = acidRainGame
33+-- \$ stack ghc ex.hs
34+-- @
35+--
36+-- Alternatively, you can just import "Streamly.Examples" and evaluate the
37+-- respective function in GHCi.
38+--
39+module Streamly.Examples
40+ (
41+ -- Reactive Programming
42+ acidRainGame
43+#ifdef EXAMPLES_SDL
44+ , circlingSquare
45+#endif
46+
47+ -- Concurrent Programming
48+ , listDirRecursive
49+ , mergeSortedStreams
50+ , searchEngineQuery
51+ )
52+where
53+
54+import Streamly.Examples.AcidRainGame
55+#ifdef EXAMPLES_SDL
56+import Streamly.Examples.CirclingSquare
57+#endif
58+import Streamly.Examples.ListDirRecursive
59+import Streamly.Examples.MergeSortedStreams
60+import Streamly.Examples.SearchEngineQuery
streamly.cabal+18−5
@@ -78,6 +78,11 @@ flag examples
78 manual: True
78 manual: True
79 default: False
79 default: False
80
80
81+flag examples-sdl
82+ description: Include examples that use SDL dependency
83+ manual: True
84+ default: False
85+
81library
86library
82 hs-source-dirs: src
87 hs-source-dirs: src
83 other-modules: Streamly.Core
88 other-modules: Streamly.Core
@@ -88,12 +93,15 @@ library
88 , Streamly.Tutorial
93 , Streamly.Tutorial
89 , Streamly
94 , Streamly
90
95
91− if flag(examples)
96+ if flag(examples) || flag(examples-sdl)
92− exposed-modules: Streamly.Examples.SearchEngineQuery
97+ exposed-modules: Streamly.Examples
98+ , Streamly.Examples.SearchEngineQuery
93 , Streamly.Examples.ListDirRecursive
99 , Streamly.Examples.ListDirRecursive
94 , Streamly.Examples.MergeSortedStreams
100 , Streamly.Examples.MergeSortedStreams
95 , Streamly.Examples.AcidRainGame
101 , Streamly.Examples.AcidRainGame
102+
103+ if flag(examples-sdl)
96− , Streamly.Examples.CirclingSquare
104+ exposed-modules: Streamly.Examples.CirclingSquare
97
105
98 default-language: Haskell2010
106 default-language: Haskell2010
99 ghc-options: -Wall
107 ghc-options: -Wall
@@ -111,6 +119,8 @@ library
111 -Wredundant-constraints
119 -Wredundant-constraints
112 -Wnoncanonical-monad-instances
120 -Wnoncanonical-monad-instances
113 -Wnoncanonical-monadfail-instances
121 -Wnoncanonical-monadfail-instances
122+ if flag(examples-sdl)
123+ cpp-options: -DEXAMPLES_SDL
114
124
115 build-depends: base >= 4.8 && < 5
125 build-depends: base >= 4.8 && < 5
116 , atomic-primops >= 0.8 && < 0.9
126 , atomic-primops >= 0.8 && < 0.9
@@ -128,12 +138,15 @@ library
128 build-depends:
138 build-depends:
129 semigroups >= 0.18 && < 0.19
139 semigroups >= 0.18 && < 0.19
130
140
131− if flag(examples)
141+ if flag(examples) || flag(examples-sdl)
132 build-Depends:
142 build-Depends:
133 http-conduit
143 http-conduit
134 , path-io
144 , path-io
135 , random
145 , random
146+
147+ if flag(examples-sdl)
148+ build-Depends:
136− , SDL >= 0.6.5 && < 0.7
149+ SDL >= 0.6.5 && < 0.7
137
150
138test-suite test
151test-suite test
139 type: exitcode-stdio-1.0
152 type: exitcode-stdio-1.0