stringbuilder-0.4.0/0000755000000000000000000000000012056653700012562 5ustar0000000000000000stringbuilder-0.4.0/LICENSE0000644000000000000000000000207012056653700013566 0ustar0000000000000000Copyright (c) 2011, 2012 Simon Hengel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. stringbuilder-0.4.0/stringbuilder.cabal0000644000000000000000000000162012056653700016422 0ustar0000000000000000name: stringbuilder version: 0.4.0 synopsis: A writer monad for multi-line string literals description: category: Testing license: MIT license-file: LICENSE copyright: (c) 2011, 2012 Simon Hengel author: Simon Hengel maintainer: Simon Hengel build-type: Simple cabal-version: >= 1.8 source-repository head type: git location: https://github.com/sol/stringbuilder library ghc-options: -Wall hs-source-dirs: src build-depends: base == 4.* exposed-modules: Data.String.Builder test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs ghc-options: -Wall -Werror hs-source-dirs: test build-depends: base , stringbuilder , hspec >= 1.3 , QuickCheck stringbuilder-0.4.0/Setup.lhs0000644000000000000000000000011412056653700014366 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain stringbuilder-0.4.0/test/0000755000000000000000000000000012056653700013541 5ustar0000000000000000stringbuilder-0.4.0/test/Spec.hs0000644000000000000000000000110112056653700014760 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} module Main (main, spec) where import Test.Hspec import Test.QuickCheck import Data.String import Data.String.Builder main :: IO () main = hspec spec spec :: Spec spec = do describe "build" $ do it "can be used to construct multi-line string literals in a monadic way" $ do build $ do "foo" "bar" "baz" `shouldBe` "foo\nbar\nbaz\n" it "works for arbitrary input" $ do property $ \l -> (build . sequence_ . map fromString) l == unlines l stringbuilder-0.4.0/src/0000755000000000000000000000000012056653700013351 5ustar0000000000000000stringbuilder-0.4.0/src/Data/0000755000000000000000000000000012056653700014222 5ustar0000000000000000stringbuilder-0.4.0/src/Data/String/0000755000000000000000000000000012056653700015470 5ustar0000000000000000stringbuilder-0.4.0/src/Data/String/Builder.hs0000644000000000000000000000165712056653700017423 0ustar0000000000000000{-# LANGUAGE TypeFamilies #-} -- | -- The `build` function can be used to construct multi-line string literals in -- a monadic way: -- -- > {-# LANGUAGE OverloadedStrings #-} -- > -- > import Data.String.Builder -- > -- > mystring :: String -- > mystring = build $ do -- > "foo" -- > "bar" -- > "baz" module Data.String.Builder ( -- * Functions build , literal -- * Types , Builder , BuilderM ) where import Data.String -- | 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 () . showString instance (a ~ ()) => IsString (BuilderM a) where fromString s = literal s >> literal "\n" -- | Run a builder. build :: Builder -> String build (BuilderM () s) = s ""