stringbuilder-0.5.0/0000755000000000000000000000000012370663340012563 5ustar0000000000000000stringbuilder-0.5.0/LICENSE0000644000000000000000000000206712370663340013575 0ustar0000000000000000Copyright (c) 2011-2014 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.5.0/stringbuilder.cabal0000644000000000000000000000161712370663340016431 0ustar0000000000000000name: stringbuilder version: 0.5.0 synopsis: A writer monad for multi-line string literals description: category: Testing license: MIT license-file: LICENSE copyright: (c) 2011-2014 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.5.0/Setup.lhs0000644000000000000000000000011412370663340014367 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain stringbuilder-0.5.0/test/0000755000000000000000000000000012370663340013542 5ustar0000000000000000stringbuilder-0.5.0/test/Spec.hs0000644000000000000000000000110112370663340014761 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.5.0/src/0000755000000000000000000000000012370663340013352 5ustar0000000000000000stringbuilder-0.5.0/src/Data/0000755000000000000000000000000012370663340014223 5ustar0000000000000000stringbuilder-0.5.0/src/Data/String/0000755000000000000000000000000012370663340015471 5ustar0000000000000000stringbuilder-0.5.0/src/Data/String/Builder.hs0000644000000000000000000000236412370663340017420 0ustar0000000000000000{-# LANGUAGE DeriveFunctor, TypeSynonymInstances, FlexibleInstances, 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 Control.Applicative import Control.Monad import Data.Monoid import Data.String -- | A writer monad for string literals. data BuilderM a = BuilderM a ShowS deriving Functor instance Applicative BuilderM where pure = return (<*>) = ap 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 () instance Monoid Builder where mempty = return () a `mappend` b = a >> b -- | 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 ""