ttc alternatives and similar packages
Based on the "Data" category.
Alternatively, view ttc alternatives based on common mentions on social networks and blogs.
10.0 9.6 ttc VS semantic-sourceParsing, analyzing, and comparing source code across many languages
9.8 8.1 ttc VS textHaskell library for space- and time-efficient operations over Unicode text.
9.8 0.0 ttc VS code-builderPackages for defining APIs, running them, generating client code and documentation.
9.7 0.0 ttc VS cassavaA CSV parsing and encoding library optimized for ease of use and high performance
9.7 0.0 ttc VS compendium-clientMu (μ) is a purely functional framework for building micro services.
9.5 5.5 ttc VS primitiveThis package provides various primitive memory-related operations.
9.3 0.0 ttc VS dependent-sumDependent sums and supporting typeclasses for comparing and displaying them
9.3 0.0 ttc VS dependent-mapDependently-typed finite maps (partial dependent products)
9.1 7.2 ttc VS text-icuThis package provides the Haskell Data.Text.ICU library, for performing complex manipulation of Unicode text.
Do you think we are missing an alternative of ttc or a related project?
TTC: Textual Type Classes
- Related Work
TTC, an initialism of Textual Type Classes, is a library that provides
Parse type classes for conversion between data types and
textual data types (strings). Use the
Read type classes for
debugging/development, and use the
Parse type classes for your
The following is a brief overview of the type classes provided by this
library. See the
API documentation on Hackage
for details and the [
examples directory](examples) for usage examples.
Render type class renders a data type as a
class Render a where render :: Textual t => a -> t
It is analogous to the
Show type class, which can be reserved for
render function returns any of the supported textual data types. Use
the textual data type that is most natural in the implementation of
instances, and return values are converted to other textual data types when
IsString type classes are not used, so use of the
String type is not required.
As a simple example, consider a
Username type that is implemented as a
module Username (Username) where import Control.Monad (unless, when) import Data.Char (isAsciiLower) import qualified Data.Text as T import Data.Text (Text) import qualified Data.TTC as TTC newtype Username = Username Text deriving (Eq, Ord, Show) instance TTC.Render Username where render (Username t) = TTC.convert t
If a username needs to be included in a
String error message, conversion is
putStrLn $ "user not found: " ++ TTC.render uname
Parse type class parses a data type from a
class Parse a where parse :: Textual t => t -> Either String a
It is analogous to the
Read type class, which can be reserved for
parse function takes any of the supported textual data types as an
argument. Use the textual data type that is most natural in the
parse instances, and arguments are converted from other
textual data types when necessary. The
IsString type class is not used, so
use of the
String type is not required.
Here is an example instance for
Username, implementing some restrictions:
instance TTC.Parse Username where parse = TTC.asT $ \t-> do unless (T.all isAsciiLower t) $ Left "username has invalid character(s)" let len = T.length t when (len < 3) $ Left "username has fewer than 3 characters" when (len > 12) $ Left "username has more than 12 characters" pure $ Username t
If a username needs to be parsed from a
String, conversion is automatic:
case TTC.parse "tcard" :: Either String Username of Right uname -> putStrLn $ "valid username: " ++ TTC.render uname Left err -> putStrLn $ "invalid username: " ++ err
It is common to create data types that have "smart constructors" to ensure
that all constructed values are valid. If the
Username constructor were
exported, it would be possible to create values with arbitrary
Username T.empty, which is not a valid
Username. Smart constructors
can be inconvenient when constructing constants, however, as neither runtime
error handling nor failure are desired. This library provides Template
Haskell functions that use
Parse instances to validate such constants at
Textual type class is used to convert between the following textual data
Conversion between any of these types is direct; it is not done through a
fixed textual data type (such as
Text). The key feature of this
type class is that it has a single type variable, making it easy to write
functions that accept arguments and/or returns values that may be any of the
supported textual data types.
Functions are provided to convert to/from the following other textual data types:
Rendering and Parsing
The relude library has
polymorphic versions of
as well as various type classes for converting between string types. This
does not encourage using
Read instances with syntactically valid
Haskell syntax, and it encourages the using of the
String data type.
The rio library has a
type class with a similar goal as
TTC.Render. Since the library encourages
a uniform usage of textual data types,
Display only provides functions for
Text and a builder format. It does not have a type class
Harry Garrood has an interesting series of blog posts about type classes and
- Down with Show! Part 1: Rules of thumb for when to use a type class
- Down with Show! Part 2: What's wrong with the Show type class
- Down with Show! Part 3: A replacement for Show
library has a
Validate type class that is similar to
supports conversion between arbitrary types, not just from textual data types.
Template Haskell functions are provided to perform validation at compile-time.
Result types must either have
Lift instances or equivalent implementations.
Chris Done posted a gist about implementing statically checked overloaded strings.
String Type Conversion
There are a number of libraries that simplify conversion between string types.
library converts between string types via the
Text type, using
ToText type classes. This works well in most cases, but it not optimal
when converting between
The textual library
(deprecated) converts between string types via the
String type, using a
Textual type class (which provides a
toString function) as well as the
IsString type class (which provides the
- Hackage: https://hackage.haskell.org/package/ttc
- Stackage: https://stackage.org/package/ttc
- GitHub: https://github.com/ExtremaIS/ttc-haskell
- Travis CI: https://travis-ci.com/ExtremaIS/ttc-haskell
Dependency version bounds are strictly specified according to what versions have been tested. If upper bounds need to be bumped when a new package is released or the package has been tested with earlier versions, feel free to submit an issue.
All releases are tagged in the
master branch. Release tags are signed using
[email protected] GPG key.
Issues and feature requests are tracked on GitHub: https://github.com/ExtremaIS/ttc-haskell/issues
Issues may also be submitted via email to [email protected].
This project is released under the
MIT License as specified in the
*Note that all licence references and agreements mentioned in the ttc README section above are relevant to that project's source code only.