Safe Haskell | Safe-Inferred |
---|
Minimalist implementation of type-safe formatted strings, borrowing heavily
from the implementation of the formatting
package.
Example use of this module:
>>>
:set -XOverloadedStrings
>>>
import Turtle.Format
>>>
format ("This is a "%s%" string that takes "%d%" arguments") "format" 2
"This is a format string that takes 2 arguments"
A Format
string that takes no arguments has this type:
"I take 0 arguments" :: Format r r format "I take 0 arguments" :: Text
>>>
format "I take 0 arguments"
"I take 0 arguments"
A Format
string that takes one argument has this type:
"I take "%d%" arguments" :: Format r (Int -> r) format ("I take "%d%" argument") :: Int -> Text
>>>
format ("I take "%d%" argument") 1
"I take 1 argument"
A Format
string that takes two arguments has this type:
"I "%s%" "%d%" arguments" :: Format r (Text -> Int -> r) format ("I "%s%" "%d%" arguments") :: Text -> Int -> Text
>>>
format ("I "%s%" "%d%" arguments") "take" 2
"I take 2 arguments"
- data Format a b
- (%) :: Format b c -> Format a b -> Format a c
- format :: Format Text r -> r
- makeFormat :: (a -> Text) -> Format r (a -> r)
- w :: Show a => Format r (a -> r)
- d :: Format r (Int -> r)
- u :: Format r (Word -> r)
- o :: Format r (Word -> r)
- x :: Format r (Word -> r)
- f :: Format r (Double -> r)
- e :: Format r (Double -> r)
- g :: Format r (Double -> r)
- s :: Format r (Text -> r)
- fp :: Format r (FilePath -> r)
- repr :: Show a => a -> Text
Format
makeFormat :: (a -> Text) -> Format r (a -> r)Source
Create your own format specifier