https://github.com/nwtgck/assertion-haskell
Assertion with condition string representation in Haskell.
https://github.com/nwtgck/assertion-haskell
assertions haskell haskell-library template-haskell
Last synced: 5 months ago
JSON representation
Assertion with condition string representation in Haskell.
- Host: GitHub
- URL: https://github.com/nwtgck/assertion-haskell
- Owner: nwtgck
- License: bsd-3-clause
- Created: 2018-04-15T04:12:01.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2022-01-16T04:27:25.000Z (about 4 years ago)
- Last Synced: 2024-10-11T15:12:05.103Z (over 1 year ago)
- Topics: assertions, haskell, haskell-library, template-haskell
- Language: Haskell
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# assertion
| branch | status|
| --- | --- |
| [`master`](https://github.com/nwtgck/assertion-haskell/tree/master) | [](https://travis-ci.org/nwtgck/assertion-haskell) |
| [`develop`](https://github.com/nwtgck/assertion-haskell/tree/develop) | [](https://travis-ci.org/nwtgck/assertion-haskell) |
Assertion with condition string representation in Haskell
## Install
Add this library to your `stack.yaml` like the following if you use [Stack](https://docs.haskellstack.org/en/stable/README/).
```yaml
...
extra-deps:
- git: https://github.com/nwtgck/assertion-haskell.git
commit: 4340a96555606d590d54669b9ae992a5b8c9a10d
...
```
Then, add `assertion` to your `package.yaml`.
```yaml
...
library:
dependencies:
- assertion
...
```
## Usages
### `assert`
```hs
{-# LANGUAGE QuasiQuotes #-}
import Assertion
main :: IO ()
main = do
let a = "hello"
let b = 10
let !x = [assert|a == "hello" && b > 9999999|]
putStrLn "End!"
```
```
ExampleMain.hs: Assertion failed: 'a == "hello" && b > 9999999'
```
### `staticAssert`
Assert in compile time. So code bellow should be compile error.
```hs
{-# LANGUAGE TemplateHaskell #-}
import Assertion
-- NOTE: Compile error (Good!)
main :: IO ()
main = do
-- NOTE: Compile error (Good!)
let _ = $(staticAssert (length "hello" == 99999))
putStrLn "End!"
```
Compile error will happen. Good!
```
examples/StaticAssertExample.hs:9:13: error:
• Compile time assertion failed
• In the untyped splice: $(staticAssert (length "hello" == 99999))
|
9 | let _ = $(staticAssert (length "hello" == 99999))
|
```