racket / typed-racket

Typed Racket
Other
527 stars 104 forks source link

`require/typed` duplicates effects from expanding `m`; docs unclear #1378

Open LiberalArtist opened 5 months ago

LiberalArtist commented 5 months ago

What version of Racket are you using?

8.12 [cs]

What program did you run?

#lang typed/racket
(module untyped racket/base
  (define five 5)
  (define six 6)
  (provide (all-defined-out)))
(require racket/require)
(require/typed
 (filtered-in (begin (displayln "effect!") values) 'untyped)
 [five Byte]
 [six Byte])

What should have happened?

It should have printed:

effect!

But instead, it printed:

effect!
effect!

Discussion

The documentation says that "m [the first subform of require/typed] is a module spec", but the docs don't define "module spec". In the cases I've tried, it seems to mean a require-spec in the sense of require.

If "module spec" is supposed to mean require-spec, one solution might be to use expand-import, or local-expand to #%require, then rewrite the repeated (require (only-in m [old new])) forms to something like (#%require (rename m* new old)).

Alternatively, if "module spec" is supposed to mean something else—e.g. a module path—that requirement should be enforced and documented.

In any case, in the documentation, I think the first sentence of the "Require" documentation section, "Here, m is a module spec, pred is an identifier naming a predicate, and maybe-renamed is an optionally-renamed identifier.", should be moved under the blue box for require/typed, rather than above it: I missed it when jumping to the documentation for require/typed. I also think a cross-reference link to whatever "module spec" is supposed to mean would be helpful.

I ran into this while looking into a question on Discourse, so there is some concrete interest in the functionality of a general require-spec.

racket-discourse-github-bot commented 5 months ago

This issue has been mentioned on Racket Discourse. There might be relevant details there:

https://racket.discourse.group/t/how-to-require-with-prefix-in-typed-racket/2963/7