sexp: S-Expression parsing/printing made fun and easy

[ gpl, language, library, parsing, program ] [ Propose Tags ]

See the file and the homepage for details.

[Skip to Readme]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS] 0.5, 0.6, 0.7
Dependencies attoparsec, base (>=4.4 && <4.9), bytestring, cmdargs, containers, dlist, ghc-prim, mtl, sexp, vector [details]
License GPL-3.0-only
Author Alexandru Scvortov <>
Revised Revision 1 made by Bodigrim at 2024-05-15T18:50:46Z
Category Language, Parsing
Home page
Source repo head: git clone
Uploaded by AlexandruScvortov at 2013-02-26T14:57:52Z
Reverse Dependencies 1 direct, 0 indirect [details]
Executables sexp
Downloads 2752 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for sexp-0.7

[back to package description]


S-Expression parsing/printing made fun and easy


sexp provides an S-expression data-type, and printers and parsers that work on all data-types that have Generic instances (so, everything you're ever likely to define yourself).

In order to encode/decode a custom data-type with sexp, 1) add a Generic instance for it, and 2) add an empty Sexpable instance for it. The default implementation of Sexpable's toSexp and fromSexp uses the Generic representation of the data-type to encode and decode it.

In order to print a Sexp, use printHum (for human-friendly output), or printMach (for human-unfriendly output). In order to parse a Sexp, use parse and friends.

See the documentation on Hackage for details.

% ghci
GHCi, version 7.6.2:  :? for help

λ > :set -XDeriveGeneric

λ > import Language.Sexp

λ > import GHC.Generics

λ > data MyType = Foo { unFoo :: Int, getBar :: Double } deriving ( Show, Generic )

λ > instance Sexpable MyType

λ > toSexp (Foo 23 42.0)
List [Atom "Foo",List [List [Atom "unFoo",Atom "23"],List [Atom "getBar",Atom "42.0"]]]

λ > printMach (toSexp (Foo 23 42.0))
"(Foo ((unFoo 23) (getBar \"42.0\")))"

λ > parseExn (printMach (toSexp (Foo 23 42.0)))
[List [Atom "Foo",List [List [Atom "unFoo",Atom "23"],List [Atom "getBar",Atom "42.0"]]]]

λ > fromSexp (head (parseExn (printMach (toSexp (Foo 23 42.0))))) :: Maybe MyType
Just (Foo {unFoo = 23, getBar = 42.0})


This package is on Hackage. To install it, run:

cabal update
cabal install sexp