on d29030f help sign in
84 lines 2.4 kB history raw
1-- |
2-- Module : Streamly.Data.Stream.MkType
3-- Copyright : (c) 2022 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : released
7-- Portability : GHC
8--
9-- Template Haskell macros to create custom newtype wrappers for the 'Stream'
10-- type, deriving all the usual instances.
11--
12-- To use this module, the following extensions must be enabled:
13--
14-- >>> :set -XStandaloneDeriving
15-- >>> :set -XTemplateHaskell
16-- >>> :set -XTypeFamilies
17-- >>> :set -XUndecidableInstances
18--
19-- Import this module unqualified to bring everything needed in scope without
20-- having to import several other modules. Also, "Streamly.Data.Stream" or
21-- "Streamly.Data.Stream.Prelude" must be imported @as Stream@.
22--
23-- >>> import Streamly.Data.Stream.MkType
24-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
25--
26-- Example, create an applicative type with zipping apply:
27--
28-- >>> :{
29-- zipApply = Stream.zipWith ($)
30-- $(mkZipType "ZipStream" "zipApply" False)
31-- :}
32--
33-- Example, create an applicative type with concurrent zipping apply:
34--
35-- >>> :{
36-- parApply = Stream.parApply id
37-- $(mkZipType "ParZipStream" "parApply" True)
38-- :}
39--
40-- Example, create a monad type with an eager concurrent cross product bind:
41--
42-- >>> :{
43-- parBind = flip (Stream.parConcatMap (Stream.eager True))
44-- $(mkCrossType "ParEagerStream" "parBind" True)
45-- :}
46--
47-- Instead of using these macros directly you could use the generated code as
48-- well. Use these macros in ghci to generate the required code and paste it in
49-- your package, you can customize the code as desired. See the docs of the
50-- macros below for examples about how to view the generated code.
51--
52module Streamly.Data.Stream.MkType
53 (
54 -- * Imports for Examples
55 -- $setup
57 -- * Template Haskell Macros
58 mkZipType
59 , mkCrossType
61 -- * Re-exports
62 , Read(..)
63 , MonadIO(..)
64 , MonadThrow(..)
65 , MonadReader(..)
66 , MonadTrans(..)
67 , Identity
68 , IsList
69 , IsString
70 , ap
71 )
72where
74import Data.Functor.Identity (Identity)
75import GHC.Exts (IsList, IsString)
76import Text.Read (Read(..))
78import Streamly.Internal.Data.Stream.MkType
80-- $setup
81-- >>> :m
82-- >>> import Language.Haskell.TH
83-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
84-- >>> import Streamly.Data.Stream.MkType