scanf: Easy and type-safe format strings for parsing and printing

[ library, mit, text ] [ Propose Tags ] [ Report a vulnerability ]

A lightweight library for one-off parsing and printing.

See README.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), containers (>=0.6.6 && <1), template-haskell (<3) [details]
Tested with ghc ==8.0.2, ghc ==8.4.4, ghc ==9.12.2
License MIT
Copyright 2018 Li-yao Xia
Author Li-yao Xia
Maintainer lysxia@gmail.com
Uploaded by lyxia at 2026-11-07T16:23:15Z
Category Text
Home page https://github.com/Lysxia/scanf#readme
Source repo head: git clone https://github.com/Lysxia/scanf
Distributions LTSHaskell:0.1.0.0, Stackage:0.2.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1344 total (11 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-11-07 [all 1 reports]

Readme for scanf-0.2.0.0

[back to package description]

Haskell scanf

Build Status Hackage

A lightweight library for one-off parsing and printing.

scanf [fmt|%d lazy %s and %d strict %s|]
      "3 lazy functions and 2 strict fields"
  = Just (3 :+ "functions" :+ 2 :+ "fields" :+ ())

Quasiquotes are optional. Format strings can also be defined with pure Haskell combinators.

printf (fmt_ (int . " lazy " % string . " and " % int . " strict " % string)
       (8 :+ "dogs" :+ 9 :+ "cats" :+ ())
  = "8 lazy dogs and 9 strict cats"

With quasiquotes, the following conversion strings are supported:

  • %d : signed integer (Int)
  • %l : signed integer (Integer, unbounded)
  • %f : floating point (Double)
  • %s : string of non-space characters (String)
  • %[...]: Scanset (String)
  • %c : single character (Char)
  • %% : parse/print a literal percent character

N.B.: in scanf, spaces in the format string match any number of whitespace character until the next nonspace character.


Though it also offers a printf function, scanf is thus named as there are only few other preexisting Haskell implementations, whereas many Haskell printf libraries can already be found on Hackage.

Similar to: