Skip to content

Rewrite OCaml implementation in Rust#2

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/rewrite-in-rust
Draft

Rewrite OCaml implementation in Rust#2
Copilot wants to merge 4 commits intomainfrom
copilot/rewrite-in-rust

Conversation

Copy link

Copilot AI commented Feb 12, 2026

Ports the Hindley-Milner type inference interpreter from OCaml to Rust.

Implementation

  • AST (src/ast.rs): Expression types with unary/binary ops, closures, let-bindings, conditionals
  • Lexer (src/lexer.rs): Character-based tokenizer with operator precedence tokens
  • Parser (src/parser.rs): Recursive descent parser handling operator precedence and closure syntax
  • Type Checker (src/type_check.rs): Algorithm W with:
    • Unification with occurs check for infinite type prevention
    • Substitution composition for constraint threading
    • Let-polymorphism via generalization/instantiation
  • Evaluator (src/eval.rs): Call-by-value semantics with substitution-based closures
  • CLI (src/main.rs): REPL and single-expression evaluation modes

Type Inference Example

// Polymorphic identity function
let id = x -> x in id
// Type: ($1 -> $1)

// Self-application via let-polymorphism
let id = x -> x in id id
// Type: ($1 -> $1)

// Higher-order function inference
let twice = f -> x -> f (f x) in twice
// Type: (($1 -> $1) -> ($1 -> $1))

CI/CD

Added .github/workflows/rust.yml with automated checks:

  • test: Build and run all 16 tests with dependency caching
  • fmt: Verify code formatting with cargo fmt
  • clippy: Run linter with all warnings as errors (-D warnings)

Notes

  • Thread-safe test execution via mutex (global gensym counter)
  • Deterministic variable ordering in lower() for consistent test results
  • Original OCaml implementation preserved in /lib and /bin
  • All code passes formatting and linting checks
Original prompt

This section details on the original issue you should resolve

<issue_title>Rewrite in rust</issue_title>
<issue_description>Please rewite in rust to increase blazingly fast</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 12, 2026 01:28
…luator

Co-authored-by: nyiyui <45807097+nyiyui@users.noreply.github.com>
Co-authored-by: nyiyui <45807097+nyiyui@users.noreply.github.com>
@Ashwagandhae
Copy link

@copilot make the github actions work. also make it work in web aseembly so it can run in browser.

@AvaWandersleben
Copy link

@copilot rewrite all of the code in completely Go

this is so slow and bad

@nyiyui
Copy link
Owner

nyiyui commented Feb 12, 2026

@copilot Run Rust tests in CI

@AvaWandersleben
Copy link

@copilot @copilot @copilot @copilot @copilot @copilot @copilot @copilot @copilot @copilot @copilot

Copilot AI changed the title [WIP] Rewrite code in Rust for performance improvements Rewrite OCaml implementation in Rust Feb 12, 2026
Copilot AI requested a review from nyiyui February 12, 2026 01:42
Co-authored-by: nyiyui <45807097+nyiyui@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 12, 2026

@copilot Run Rust tests in CI

Added .github/workflows/rust.yml with CI jobs for tests, formatting (cargo fmt), and linting (cargo clippy). All checks pass successfully. (4f81b9d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite in rust

4 participants