on master help sign in
Add Examples module, make SDL examples optional
commit2ed8b607783fbc365155031048acf06137e22369 authorHarendra Kumar <harendra.kumar@gmail.com> dateFri 1 Dec 2017, 14:34 (9 years ago) parentf8da13f
2 files changed+78−5
src/Streamly/Examples.hs+60 streamly.cabal+18−5
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
7878 manual: True
7979 default: False
8080
81+flag examples-sdl
82+ description: Include examples that use SDL dependency
83+ manual: True
84+ default: False
85+
8186library
8287 hs-source-dirs: src
8388 other-modules: Streamly.Core
@@ -88,12 +93,15 @@ library
8893 , Streamly.Tutorial
8994 , Streamly
9095
91− if flag(examples)
92− exposed-modules: Streamly.Examples.SearchEngineQuery
96+ if flag(examples) || flag(examples-sdl)
97+ exposed-modules: Streamly.Examples
98+ , Streamly.Examples.SearchEngineQuery
9399 , Streamly.Examples.ListDirRecursive
94100 , Streamly.Examples.MergeSortedStreams
95101 , Streamly.Examples.AcidRainGame
96− , Streamly.Examples.CirclingSquare
102+
103+ if flag(examples-sdl)
104+ exposed-modules: Streamly.Examples.CirclingSquare
97105
98106 default-language: Haskell2010
99107 ghc-options: -Wall
@@ -111,6 +119,8 @@ library
111119 -Wredundant-constraints
112120 -Wnoncanonical-monad-instances
113121 -Wnoncanonical-monadfail-instances
122+ if flag(examples-sdl)
123+ cpp-options: -DEXAMPLES_SDL
114124
115125 build-depends: base >= 4.8 && < 5
116126 , atomic-primops >= 0.8 && < 0.9
@@ -128,12 +138,15 @@ library
128138 build-depends:
129139 semigroups >= 0.18 && < 0.19
130140
131− if flag(examples)
141+ if flag(examples) || flag(examples-sdl)
132142 build-Depends:
133143 http-conduit
134144 , path-io
135145 , random
136− , SDL >= 0.6.5 && < 0.7
146+
147+ if flag(examples-sdl)
148+ build-Depends:
149+ SDL >= 0.6.5 && < 0.7
137150
138151test-suite test
139152 type: exitcode-stdio-1.0