The validated-literals package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Warnings:

To disallow invalid input it is common to define (new)types with hidden data constructors. Forcing the user to go through a smart-constructor that enforces invariants and returns Maybe ResultType, preventing the construction of data with invalid values.

However, it is __also__ common to want to include literal values of such types in source text. Things of textual literals for HTML, HTTP, etc. In such cases smart-constructors force us to handle potential conversion failures at runtime, or abusing functions like fromJust to break away all the safety smart-constructors provide. All this despite the fact that we can statically know at compile time that the conversion will always succeed or always fails.

This package provides a typeclasses for using TH to validate the correctness of provided literals at compile. This lets you define, e.g., newtype Even = Even Integer and write:

x :: Even
x = $$(valid 38)

This will check, at compile time, that the provided Integer is, in fact, even and unwrap it from Maybe, avoiding the runtime check.

Properties

Versions0.1.0, 0.2.0, 0.2.0
Change logNone available
Dependenciesbase (==4.8.*), bytestring (==0.10.*), template-haskell [details]
LicenseBSD3
CopyrightCopyright © 2015 Merijn Verstraaten
AuthorMerijn Verstraaten
MaintainerMerijn Verstraaten <merijn@inconsistent.nl>
CategoryData
Home pagehttps://github.com/merijn/validated-literals
Bug trackerhttps://github.com/merijn/validated-literals/issues
Source repositoryhead: hg clone https://bitbucket.org/merijnv/validated-literals
head: git clone git+ssh://github.com:merijn/validated-literals
UploadedFri Sep 11 15:26:11 UTC 2015 by MerijnVerstraaten

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees