safe-printf alternatives and similar packages
Based on the "Text" category.
Alternatively, view safe-printf alternatives based on common mentions on social networks and blogs.
-
skylighting
A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions -
double-conversion
A fast Haskell library for converting between double precision floating point numbers and text strings. It is implemented as a binding to the V8-derived C++ double-conversion library.
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of safe-printf or a related project?
README
safe-printf -- Well-typed, variadic and flexible printf functions for Haskell
What is this?
Haskell's standard Text.Printf
module provides variadic printf
function but not type-safe.
This library provides an alternative for this, more type-safe version of printf
function,
combinators and quasiquoters.
The current implementation is just a proof-of-concept, so it is not so efficient and provides
APIs only for String
value generation. In future, we will support Text
types and improve the effiiciency.
Install
$ git clone https://github.com/konn/safe-printf.git
$ cd safe-printf
$ cabal install
<!--
$ cabal install safe-printf
-->
Usage
We provide two interfaces to construct format: smart constructors and quasiquoters.
Smart constructors
You need OverloadedStrings
extension.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Text.Printf.Safe (printf, (%), (><))
import Text.Printf.Safe.Combinators (b', d, _S)
main = do
putStrLn $ printf ("1 + 2 = " %d >< " and 0 == 1 is " %_S >< "." ) (1 + 2) (0 == 1)
putStrLn $ printf ("42 is " % b' '0' 10 >< "in binary.") 42
putStrLn $ printf ("48% of people answers that the negation of True is" %(show . not) >< ".") True
Quasiquote interface
Quiasiquote interface provides more readable way for generating formats.
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Text.Printf.Safe (printf, fmt)
main = do
putStrLn $ printf [fmt|1 + 2 = %d and 0 == 1 is %S.|] (1 + 2) (0 == 1)
putStrLn $ printf [fmt|42 is %010b in binary.|] 42
putStrLn $ printf [fmt|48%% of people answers that the negation of True is %{show . not}.|] True
TODO
- Support
Text
and perhapsBuilder
. - Improve efficiency.
- Provide IO functions?
Licence
BSD3
Copyright
(c) Hiromi ISHII 2015