https://github.com/avanov/liquid-haskell-parsing-demo
A small demo of how Liquid Haskell and refinement types can aid API design
https://github.com/avanov/liquid-haskell-parsing-demo
Last synced: about 1 year ago
JSON representation
A small demo of how Liquid Haskell and refinement types can aid API design
- Host: GitHub
- URL: https://github.com/avanov/liquid-haskell-parsing-demo
- Owner: avanov
- License: agpl-3.0
- Created: 2021-01-21T02:01:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-22T21:29:30.000Z (over 5 years ago)
- Last Synced: 2024-10-12T06:59:09.716Z (over 1 year ago)
- Language: Nix
- Homepage:
- Size: 20.5 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Liquid Haskell Example
======================
This is a self-contained [Liquid Haskell](https://ucsd-progsys.github.io/liquidhaskell-blog/) example.
```bash
nix-shell --run "make run"
```
Consider the function [`apiCallProvideRedundancy`](https://github.com/avanov/liquid-haskell-parsing-demo/blob/460f1fd8e352fe815ea41920d9a3683d10e3026d/app/Main.hs#L36-L42).
Imagine it's a part of "Core API" that needs to be safe and free from redundant case-analysis of input data.
Liquid Haskell helps us to express types and filter values based on predicates that go beyond `NonEmpty` kinds of constructors.
As soon as I declare that `type Destinations` is a list of at least two non-empty textual values,
the compiler requires me to prove that the data I call `apiCallProvideRedundancy` with does satisfy
that criteria of the firsrt argument.
Hence [the helper parsing functions](https://github.com/avanov/liquid-haskell-parsing-demo/blob/460f1fd8e352fe815ea41920d9a3683d10e3026d/app/Main.hs#L49-L76)
have to exist at the boundaries of my API, and not somewhere inside `apiCallProvideRedundancy`.