racket / racket/typed-racket

Locally-defined types can't be inferred as a polymorphic argument in other module

Open
#262 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

The file below gives the error Type Checker: Foo is not bound as a type in: foo on the last line.

#lang typed/racket

(module m typed/racket
  (define foo
    (let ()
      (define-type Foo (List (U Foo One)))

      (ann (list 1) Foo)))

  (provide foo))

(require 'm)

(: f (∀ (A) (→ (List A) Any)))
(define (f x) 2)

(f foo)

When moving the call to f and its definition inside the module m, the error does not occur.

It seems that for this problem to occur, the type Foo:

  • Has to be locally declared (inside a let)
  • Has to be recursive (otherwise I guess it gets expanded where used, and its name isn't used anymore)
  • Has to be used in a separate module (here it's inferred as the type argument for a polymorphic type)

I hit this problem while writing a macro that defines recursive types, and does so locally so that the macro can be used anywhere and not just at the top-level. Converting to using Rec is not really possible in my case, because there are several mutually recursive types, and their expansion would be very big.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the typed/racket reproducer in the issue, focusing on the local recursive Foo in module m and the polymorphic (f foo) call. Trace why the exported foo is rejected as the inferred argument type; done when the final call no longer reports Foo as unbound while the in-module call remains valid.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.