string-combinators 0.2 → 0.3
raw patch · 3 files changed
+59/−105 lines, 3 filesdep −bytestringdep −dstringdep −prettydep ~base
Dependencies removed: bytestring, dstring, pretty, text
Dependency ranges changed: base
Files
- Data/String/Combinators.hs +54/−33
- Data/String/Stringable.hs +0/−54
- string-combinators.cabal +5/−18
Data/String/Combinators.hs view
@@ -32,12 +32,14 @@ , between , paren+ , thenParen , brackets , braces , angleBrackets , quotes , doubleQuotes + -- * From characters , char @@ -69,29 +71,31 @@ where -import Data.String-import Data.Monoid+import Data.String (IsString, fromString)+import Data.Monoid (Monoid, mempty, mappend) ---------------------------------------------------------------------- -- Combining ---------------------------------------------------------------------- --- | Put two strings besides eachother.+-- | Put two string-likes besides eachother.+-- -- Note that '<>' is just a synonym for 'mappend'. (<>) :: Monoid s => s -> s -> s (<>) = mappend -- | @mid m x y@ Puts @x@ and @y@ around @m@.--- Note that: @mid m x y =@ 'between' @x y m@+--+-- Note that: @mid m x y =@ 'between' @x y m@. mid :: Monoid s => s -> (s -> s -> s) mid m x y = between x y m --- | Put two strings besides eachother separated by a space.+-- | Put two string-likes besides eachother separated by a space. (<+>) :: (Monoid s, IsString s) => s -> s -> s (<+>) = mid space --- | Put two strings above eachother.+-- | Put two string-likes above eachother. ($$) :: (Monoid s, IsString s) => s -> s -> s ($$) = mid newline @@ -99,19 +103,19 @@ infixl 6 <+> infixl 5 $$ --- | List version of '<>'+-- | List version of '<>'. hcat :: Monoid s => [s] -> s hcat = foldr (<>) mempty --- | List version of '<+>'+-- | List version of '<+>'. hsep :: (Monoid s, IsString s) => [s] -> s hsep = foldr (<+>) mempty --- | List version of '$$'+-- | List version of '$$'. vcat :: (Monoid s, IsString s) => [s] -> s vcat = foldr ($$) mempty --- | @punctuate p [d1, ... dn] = [d1 \<> p, d2 \<> p, ... dn-1 \<> p, dn]@+-- | @punctuate p [d1, ... dn] = [d1 \<> p, d2 \<> p, ... dn-1 \<> p, dn]@. -- Shamelessly copied from 'pretty': punctuate :: (Monoid s) => s -> [s] -> [s]@@ -126,98 +130,111 @@ -- Wrapping in delimiters ---------------------------------------------------------------------- --- | @between b c s@ wraps the string @s@ between @b@ and @c@+-- | @between b c s@ wraps the string-like @s@ between @b@ and @c@. between :: (Monoid s) => s -> s -> (s -> s) between open close x = open <> x <> close --- | wrap a string in @(...)@+-- | Wrap a string-like in @(...)@. paren :: (Monoid s, IsString s) => s -> s paren = between "(" ")" --- | wrap a string in @[...]@+-- | Wrap a string-like in @[...]@. brackets :: (Monoid s, IsString s) => s -> s brackets = between "[" "]" --- | wrap a string in @{...}@+-- | Wrap a string-like in @{...}@. braces :: (Monoid s, IsString s) => s -> s braces = between "{" "}" --- | wrap a string in @\<...\>@+-- | Wrap a string-like in @\<...\>@. angleBrackets :: (Monoid s, IsString s) => s -> s angleBrackets = between "<" ">" --- | wrap a string in @\'...\'@+-- | Wrap a string-like in @\'...\'@. quotes :: (Monoid s, IsString s) => s -> s quotes = between "'" "'" --- | wrap a string in @\"...\"@+-- | Wrap a string-like in @\"...\"@. doubleQuotes :: (Monoid s, IsString s) => s -> s doubleQuotes = between "\"" "\"" +{- | Like 'showParen' conditionally wraps a string in @(...)@++This function is supposed to be used infix as in:++@+(precedence >= 10) \`thenParen\` (\"fun\" \<+\> \"arg\")+@+-}+thenParen :: (Monoid s, IsString s) => Bool -> s -> s+thenParen True = paren+thenParen False = id++ ---------------------------------------------------------------------- -- From characters ---------------------------------------------------------------------- --- | convert a character to a string+-- | Convert a character to a string-like. char :: IsString s => Char -> s char c = fromString [c] --- | A ';' character+-- | A ';' character. semi :: IsString s => s semi = char ';' --- | A ':' character+-- | A ':' character. colon :: IsString s => s colon = char ':' --- | A ',' character+-- | A ',' character. comma :: IsString s => s comma = char ',' --- | A ' ' character+-- | A ' ' character. space :: IsString s => s space = char ' ' --- | A '\n' character+-- | A '\n' character. newline :: IsString s => s newline = char '\n' --- | A '=' character+-- | A '=' character. equals :: IsString s => s equals = char '=' --- | A '(' character+-- | A '(' character. lparen :: IsString s => s lparen = char '(' --- | A ')' character+-- | A ')' character. rparen :: IsString s => s rparen = char ')' --- | A '[' character+-- | A '[' character. lbrack :: IsString s => s lbrack = char '[' --- | A ']' character+-- | A ']' character. rbrack :: IsString s => s rbrack = char ']' --- | A '{' character+-- | A '{' character. lbrace :: IsString s => s lbrace = char '{' --- | A '}' character+-- | A '}' character. rbrace :: IsString s => s rbrace = char '}' --- | A \'<\' character+-- | A \'<\' character. labrack :: IsString s => s labrack = char '<' --- | A \'>\' character+-- | A \'>\' character. rabrack :: IsString s => s rabrack = char '>' @@ -231,19 +248,23 @@ fromShow :: (Show a, IsString s) => a -> s fromShow = fromString . show -+-- | Convert an Int to a string-like. int :: IsString s => Int -> s int = fromShow +-- | Convert an Integer to a string-like. integer :: IsString s => Integer -> s integer = fromShow +-- | Convert a Float to a string-like. float :: IsString s => Float -> s float = fromShow +-- | Convert a Double to a string-like. double :: IsString s => Double -> s double = fromShow +-- | Convert a Rational to a string-like. rational :: IsString s => Rational -> s rational = fromShow
− Data/String/Stringable.hs
@@ -1,54 +0,0 @@-{-# LANGUAGE TypeSynonymInstances #-}---------------------------------------------------------------------------------- |--- Module : Data.String.Stringable--- Copyright : (c) 2009 Bas van Dijk--- License : BSD-style (see the file LICENSE)------ Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>--- Stability : Stable--- Portability : Requires TypeSynonymInstances-----------------------------------------------------------------------------------module Data.String.Stringable (Stringable(..)) where---import Data.String--import qualified Data.ByteString.Char8 as B-import qualified Data.DString as DS-import qualified Data.Text as T-import qualified Text.PrettyPrint as PP----- | Class of types that can be converted to and from a String.-class IsString s => Stringable s where- toString :: s -> String---instance Stringable String where- toString = id--instance Stringable B.ByteString where- toString = B.unpack--instance Stringable PP.Doc where- toString = PP.render--instance Stringable ShowS where- toString s = s []--instance Stringable DS.DString where- toString = DS.toString--instance Stringable T.Text where- toString = T.unpack---instance IsString ShowS where- fromString = showString--instance IsString PP.Doc where- fromString = PP.text
string-combinators.cabal view
@@ -1,17 +1,11 @@ Name: string-combinators-Version: 0.2+Version: 0.3 Synopsis: Polymorphic functions to build and combine stringlike values Description: string-combinators provides handy polymorphic functions- to build and combine stringlike values.+ to build and combine string-like values. .- All functions are polymorphic in their string type+ All functions are polymorphic in their string-like type but usually have a Monoid or IsString constraint.- .- Conditionally a module Data.String.Stringable is provided.- This module exports a typeclass Stringable- for converting values to and from Strings.- A bunch of instances is defined- for some common stringlike types. Category: Data License: BSD3 License-file: LICENSE@@ -21,20 +15,13 @@ Cabal-version: >= 1.6 Build-Type: Simple Stability: experimental+Extra-source-files: LICENSE Source-repository head Type: darcs Location: http://code.haskell.org/~basvandijk/code/string-combinators/ -Flag Stringable- Description: Include the Data.String.Stringable module- Library- Build-Depends: base+ Build-Depends: base == 4.* Exposed-modules: Data.String.Combinators-- if flag(Stringable)- Build-Depends: bytestring, dstring, text, pretty- Exposed-modules: Data.String.Stringable- Ghc-options: -O2 -Wall