Skip to content

typecheck: Minor doc updates for consistency with other functions #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions docs/builtins/Repl/typecheck.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
## typecheck

Use `(typecheck "my-module")` to run the pact static typechecker on some module `my-module`
Use `typecheck` to run the Pact static type checker on the `module` you specify.

### Basic syntax

For some module `foo`:
To run the static type checker on the `module` specified, use the following syntax:

```pact
(module foo GOV
(defcap GOV () true)

(defun plus-one (a) (+ a 1))
)
```

To statically typecheck `foo`, call

```pact
(typecheck "foo")
(typecheck module)
```

If your module `foo` is under `(namespace "bar)`, then call `(typecheck "bar.foo")`

## Arguments
### Arguments

Use the following arguments when calling `typecheck`:
Use the following argument when calling the `typecheck` function:

| Argument | Type | Description |
|----------|------|-------------|
| `module` | string | The module to run the static typechecker on |
| `module` | string | Specifies the name of the module to run the static type checker on. |

## Return value
### Return value

On typechecking succeess, `typecheck` returns the unit value `()`. Otherwise, it will throw an error.
If type checking for the module is successful, the `typecheck` function returns the unit value `()`.
If type checking fails, the `typecheck` function throws an error and ends execution.

## Examples
### Examples

The following example demonstrates how to call the static typechecker:


For some module `foo`:
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:

```pact
(module foo GOV
(module rewards GOV
(defcap GOV () true)

(defun plus-one (a) (+ a 1))
(defun multiplier (points) (* points 10))
)

(typecheck "foo")
(typecheck "rewards")
```

If you execute the code in the file by running `pact rewards.repl --trace`, you see the results of type checking for the module.
For example:

```bash
rewards.repl:0:0-4:1:Trace: Loaded module rewards, hash d6qkp1SyjmFCUofnsMpdV2W3IOLH8VA9lg0Dqv4cN_M
rewards.repl:6:0-6:21:Trace: Typechecking successful for module rewards
Load successful
```

If you specify a namespace before the module declaration, you must include the namespace when you call the `typecheck` function.
For example, if the `rewards` module declaration comes after entering the `(namespace "develop")` namespace, you would call the `typecheck` function like this:

```pact
(typecheck "develop.rewards")
```