Popularity
6.5
Declining
Activity
3.6
-
20
3
3

Monthly Downloads: 30
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Data    
Latest version: v0.3.0

validated-literals alternatives and similar packages

Based on the "Data" category.
Alternatively, view validated-literals alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of validated-literals or a related project?

Add another 'Data' Package

README

validated-literals: Compile-time checking for partial smart-constructors

BSD3 Hackage hackage-ci Build Status

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.


*Note that all licence references and agreements mentioned in the validated-literals README section above are relevant to that project's source code only.