# pfcl-typechecker

PFCL Hindley-Milner type inference using catalog signatures as the type environment.

## Overview

This crate provides:

- **Type inference** — Hindley-Milner algorithm W with let-polymorphism
- **Unification** — Type variable substitution and constraint solving
- **Catalog integration** — Uses function catalog signatures as the type environment
- **Error reporting** — Type mismatch errors with source locations

## Build

```bash
# From workspace root
cargo build -p pfcl-typechecker

# Or from this directory
cargo build
```

## Test

```bash
# Run all 48 tests (15 unit + 33 integration)
cargo test -p pfcl-typechecker

# Run only unit tests
cargo test -p pfcl-typechecker --lib

# Run integration tests
cargo test -p pfcl-typechecker --test integration

# With output
cargo test -p pfcl-typechecker -- --nocapture
```

## Usage as Library

```rust
use pfcl_typechecker::{TypeChecker, TypeEnv};

// Create type environment from catalog
let env = TypeEnv::from_catalog(&catalog);

// Type check a resolved expression
let checker = TypeChecker::new(&env);
let ty = checker.infer(&resolved_expr)?;
```

## Dependencies

None — zero external dependencies.

## Module Structure

- `typechecker.rs` — Main inference logic (Algorithm W)
- `types.rs` — Type representation (Type, TypeVar, TypeScheme)
- `unify.rs` — Unification algorithm
- `env.rs` — Type environment

## Integration Tests

The `tests/` directory contains integration tests that verify end-to-end type checking:

```bash
cargo test -p pfcl-typechecker --test integration
```
