https://github.com/danieljharvey/purescript-refined
Purescript refinement types with runtime checking
https://github.com/danieljharvey/purescript-refined
purescript refined type-level-programming
Last synced: about 1 month ago
JSON representation
Purescript refinement types with runtime checking
- Host: GitHub
- URL: https://github.com/danieljharvey/purescript-refined
- Owner: danieljharvey
- Created: 2019-04-09T12:39:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-17T08:35:00.000Z (over 3 years ago)
- Last Synced: 2025-11-09T22:25:30.879Z (4 months ago)
- Topics: purescript, refined, type-level-programming
- Language: PureScript
- Homepage:
- Size: 23.4 KB
- Stars: 25
- Watchers: 0
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Purescript Refined
A Purescript port of [Refined](http://hackage.haskell.org/package/refined).
Allows one to create types that restrain the values inside, and automatically generate validators for them.
For instance:
```haskell
type DiceRoll = Refined (FromTo D1 D6) Int
invalidDiceRoll :: Either RefinedError DiceRoll
invalidDiceRoll = refine 8
-- invalidDiceRoll = Left (FromToError 1 6 8)
validDiceRoll :: Either RefinedError DiceRoll
validDiceRoll = refine 5
-- validDiceRoll = Right DiceRoll
diceRollToInt :: DiceRoll -> Int
diceRollToInt = unrefine
```
This package also contains `EncodeJson` and `DecodeJson` instances for Argonaut so that JSON data can be validated, and `Arbitrary` instances for use with QuickCheck.
Documentation can be found on [Pursuit](https://pursuit.purescript.org/packages/purescript-refined/0.1.2)