stringbuilder 0.2.0 → 0.3.0
raw patch · 2 files changed
+26/−16 lines, 2 filesdep +stringbuilderdep −transformers
Dependencies added: stringbuilder
Dependencies removed: transformers
Files
- src/Data/String/Builder.hs +23/−12
- stringbuilder.cabal +3/−4
src/Data/String/Builder.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE GeneralizedNewtypeDeriving, GADTs #-}+{-# LANGUAGE GADTs #-} -- |--- `build` can be used to construct multi-line string literals in a monadic--- way.+-- The `build` function can be used to construct multi-line string literals in+-- a monadic way: -- -- > {-# LANGUAGE OverloadedStrings #-} -- >@@ -12,23 +12,34 @@ -- > "foo" -- > "bar" -- > "baz"------ `return` and `>>=` are not useful in this context!-module Data.String.Builder (build, Builder, BuilderM) where+module Data.String.Builder (+-- * Functions+ build+, literal+-- * Types+, Builder+, BuilderM+) where import Data.String-import Control.Monad.Trans.Writer -newtype BuilderM a = BuilderM { runBuilderM :: Writer String a }- deriving Monad+-- | A writer monad for string literals.+data BuilderM a = BuilderM a ShowS +instance Monad BuilderM where+ return a = BuilderM a id+ BuilderM a xs >>= f = case f a of+ BuilderM b ys -> BuilderM b (xs . ys)+ type Builder = BuilderM () +-- | Add a literal string. literal :: String -> Builder-literal = BuilderM . tell+literal = BuilderM () . showString instance (a ~ ()) => IsString (BuilderM a) where- fromString s = literal s >> literal "\n" >> return ()+ fromString s = literal s >> literal "\n" +-- | Run a builder. build :: Builder -> String-build = snd . runWriter . runBuilderM+build (BuilderM () s) = s ""
stringbuilder.cabal view
@@ -1,5 +1,5 @@ name: stringbuilder-version: 0.2.0+version: 0.3.0 synopsis: A monadic builder for multi-line string literals description: <https://github.com/sol/stringbuilder#readme> category: Testing@@ -22,7 +22,6 @@ src build-depends: base < 5- , transformers exposed-modules: Data.String.Builder @@ -34,9 +33,9 @@ ghc-options: -Wall -Werror hs-source-dirs:- src, test+ test build-depends: base- , transformers+ , stringbuilder , hspec >= 1.3 , QuickCheck