blob: 5d551e5a49ab32867704e4cac2d885a18c043b58 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
yants
=====
This is a tiny type-checker for data in Nix, written in Nix.
# Features
* Checking of primitive types (`int`, `string` etc.)
* Checking polymorphic types (`option`, `list`, `either`)
* Defining & checking struct/record types
* Defining & matching enum types
* Defining & matching sum types
* Defining function signatures (including curried functions)
* Types are composable! `option string`! `list (either int (option float))`!
* Type errors also compose!
Currently lacking:
* Any kind of inference
* Convenient syntax for attribute-set function signatures
## Primitives & simple polymorphism
![simple](screenshots/simple.png)
## Structs
![structs](screenshots/structs.png)
## Nested structs!
![nested structs](screenshots/nested-structs.png)
## Enums!
![enums](screenshots/enums.png)
## Functions!
![functions](screenshots/functions.png)
# Usage
Yants can be imported from its `default.nix`. A single attribute (`lib`) can be
passed, which will otherwise be imported from `<nixpkgs>`.
Examples for the most common import methods would be:
1. Import into scope with `with`:
```nix
with (import ./default.nix {});
# ... Nix code that uses yants ...
```
2. Import as a named variable:
```nix
let yants = import ./default.nix {};
in yants.string "foo" # or other uses ...
````
3. Overlay into `pkgs.lib`:
```nix
# wherever you import your package set (e.g. from <nixpkgs>):
import <nixpkgs> {
overlays = [
(self: super: {
lib = super.lib // { yants = import ./default.nix { inherit (super) lib; }; };
})
];
}
# yants now lives at lib.yants, besides the other library functions!
```
Please see my [Nix one-pager](https://github.com/tazjin/nix-1p) for more generic
information about the Nix language and what the above constructs mean.
# Stability
The current API of Yants is **not yet** considered stable, but it works fine and
should continue to do so even if used at an older version.
Yants' tests use Nix versions above 2.2 - compatibility with older versions is
not guaranteed.
|