Make “sublibrary” standard terminology in docs
[cabal.git] / Cabal / src / Distribution / ZinzaPrelude.hs
blobbc1d0ed6a709faf5b93f9806194dbca52e21af16
1 -- | A small prelude used in @zinza@ generated
2 -- template modules.
3 module Distribution.ZinzaPrelude
4 ( Writer
5 , execWriter
6 , tell
8 -- * Re-exports
9 , forM_
10 , Generic
11 , PackageName
12 , Version
13 , prettyShow
14 ) where
16 import Distribution.Compat.Prelude
17 import Prelude ()
19 import Control.Monad (forM_)
20 import Distribution.Pretty (prettyShow)
21 import Distribution.Types.PackageName (PackageName)
22 import Distribution.Types.Version (Version)
24 newtype Writer a = W {unW :: ShowS -> (ShowS, a)}
26 instance Functor Writer where
27 fmap = liftM
29 instance Applicative Writer where
30 pure x = W $ \ss -> (ss, x)
31 (<*>) = ap
33 instance Monad Writer where
34 return = pure
35 m >>= k = W $ \s1 ->
36 let (s2, x) = unW m s1
37 in unW (k x) s2
38 {-# INLINE (>>=) #-}
40 execWriter :: Writer a -> String
41 execWriter w = fst (unW w id) ""
43 tell :: String -> Writer ()
44 tell s = W $ \s' -> (s' . showString s, ())