|
1 |
| -## typecheck |
| 1 | +# typecheck |
2 | 2 |
|
3 |
| -Use `(typecheck "my-module")` to run the pact static typechecker on some module `my-module` |
| 3 | +Use `typecheck` to run the Pact static type checker on a specified `module` name. |
4 | 4 |
|
5 |
| -### Basic syntax |
| 5 | +## Basic syntax |
6 | 6 |
|
7 |
| -For some module `foo`: |
| 7 | +To run the static type checker on a specified `module` name, use the following syntax: |
8 | 8 |
|
9 | 9 | ```pact
|
10 |
| -(module foo GOV |
11 |
| - (defcap GOV () true) |
12 |
| -
|
13 |
| - (defun plus-one (a) (+ a 1)) |
14 |
| -) |
15 |
| -``` |
16 |
| - |
17 |
| -To statically typecheck `foo`, call |
18 |
| - |
19 |
| -```pact |
20 |
| -(typecheck "foo") |
| 10 | +(typecheck module) |
21 | 11 | ```
|
22 | 12 |
|
23 |
| -If your module `foo` is under `(namespace "bar)`, then call `(typecheck "bar.foo")` |
24 |
| - |
25 | 13 | ## Arguments
|
26 | 14 |
|
27 |
| -Use the following arguments when calling `typecheck`: |
| 15 | +Use the following argument when calling the `typecheck` function: |
28 | 16 |
|
29 | 17 | | Argument | Type | Description |
|
30 | 18 | |----------|------|-------------|
|
31 |
| -| `module` | string | The module to run the static typechecker on | |
| 19 | +| `module` | string | Specifies the name of the module to run the static type checker on. | |
32 | 20 |
|
33 | 21 | ## Return value
|
34 | 22 |
|
35 |
| -On typechecking succeess, `typecheck` returns the unit value `()`. Otherwise, it will throw an error. |
| 23 | +If type checking for the module is successful, the `typecheck` function returns the unit value `()`. |
| 24 | +If type checking fails, the function returns an error. |
36 | 25 |
|
37 | 26 | ## Examples
|
38 | 27 |
|
39 |
| -The following example demonstrates how to call the static typechecker: |
40 |
| - |
41 |
| - |
42 |
| -For some module `foo`: |
| 28 | +The following example demonstrates a simple `.repl` file with the module declaration for a `rewards` module that then calls the static type checker to check the `rewards` module: |
43 | 29 |
|
44 | 30 | ```pact
|
45 |
| -(module foo GOV |
| 31 | +(module rewards GOV |
46 | 32 | (defcap GOV () true)
|
47 | 33 |
|
48 |
| - (defun plus-one (a) (+ a 1)) |
| 34 | + (defun multiplier (points) (* points 10)) |
49 | 35 | )
|
50 | 36 |
|
51 |
| -(typecheck "foo") |
| 37 | +(typecheck "rewards") |
| 38 | +``` |
| 39 | + |
| 40 | +If you execute the code in the file by running `pact rewards.repl --trace`, you see the results of type checking for the module. |
| 41 | +For example: |
| 42 | + |
| 43 | +```bash |
| 44 | +rewards.repl:0:0-4:1:Trace: Loaded module rewards, hash d6qkp1SyjmFCUofnsMpdV2W3IOLH8VA9lg0Dqv4cN_M |
| 45 | +rewards.repl:6:0-6:21:Trace: Typechecking successful for module rewards |
| 46 | +Load successful |
52 | 47 | ```
|
| 48 | + |
| 49 | +If you specify a namespace before the module declaration, you must include the namespace when you call the `typecheck` function. |
| 50 | +For example, if the `rewards` module declaration comes after entering the `(namespace "develop")` namespace, you would call the `typecheck` function like this: |
| 51 | + |
| 52 | +```pact |
| 53 | +(typecheck "develop.rewards") |
| 54 | +``` |
0 commit comments