Skip to content
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

Values handling in non-function contexts causes errors #1409

Open
NoahStoryM opened this issue Nov 3, 2024 · 0 comments
Open

Values handling in non-function contexts causes errors #1409

NoahStoryM opened this issue Nov 3, 2024 · 0 comments

Comments

@NoahStoryM
Copy link
Contributor

NoahStoryM commented Nov 3, 2024

What version of Racket are you using?
8.14 [cs]

What program did you run?

  1. Using Values in the return type of let:
Welcome to Racket v8.14 [cs].
> (let #:∀ (a ...) ([thk : (→ (Values a ... a)) (λ () (values 1 2 3))])
    (thk))
- : (values Integer Integer Integer) [more precisely: (Values One Positive-Byte Positive-Byte)]
1
2
3

> (let #:∀ (a ...) ([thk : (→ (Values a ... a)) (λ () (values 1 2 3))]) : (Values a ... a)
    (thk))
string:1:80: Type Checker: Error in macro expansion -- parse error in type;
 type variable must be used with ...
  variable: a
  in: a
 [,bt for context]

Equivalent code that works by wrapping Values inside a function type:

> (: f (∀ (a ...) (→ (→ (Values a ... a)) (Values a ... a))))
> (define (f thk) (thk))
> (f (λ () (values 1 2 3)))
- : (values Integer Integer Integer) [more precisely: (Values One Positive-Byte Positive-Byte)]
1
2
3

> (: g (∀ (a ...) (→ (→ (Values a ... a)) (Values a ... a))))
> (define (g thk1)
    (: thk2 (→ (Values a ... a)))
    (define thk2 thk1)
    (thk2))
> (g (λ () (values 1 2 3)))
- : (values Integer Integer Integer) [more precisely: (Values One Positive-Byte Positive-Byte)]
1
2
3
  1. Using Values in let/cc:
Welcome to Racket v8.14 [cs].
> (require typed/racket/unsafe)
> (unsafe-require/typed racket/base
    [call-in-continuation
     (∀ (a ...)
        (case→ (→ (→ a ... a Nothing) (→ (Values a ... a)) Nothing)
               (→ (→ Any * Nothing) (→ AnyValues) Nothing)))])

> (: h (∀ (a ...) (→ (→ (Values a ... a)) (Values a ... a))))
> (define (h thk)
    (let/cc k : (Values a ... a)
      (call-in-continuation k thk)))
string:2:2: Type Checker: Polymorphic function `call/cc' could not be applied to arguments:
Types: (-> (-> Nothing) (values))  -> (values)
       (-> (-> Nothing) (values)) Prompt-TagTop  -> (values)
       (-> (-> a c ... c Nothing) (values b c ... c))  -> (values (U a b) c ... c)
       (-> (-> a c ... c Nothing) (values b c ... c)) Prompt-TagTop  -> (values (U a b) c ... c)
Arguments: (-> (-> a ... a Nothing) Nothing)
Expected result: (values)
  in: (let/cc k : (Values a ... a) (call-in-continuation k thk))
 [,bt for context]

A working alternative:

> (: i (∀ (a ...) (→ (→ (Values a ... a)) (→ (→ a ... a Nothing) (Values a ... a)))))
> (define ((i thk) k) (call-in-continuation k thk))
> (call/cc (i (λ () (values 1 2 3))))
- : (values Integer Integer Integer) [more precisely: (Values One Positive-Byte Positive-Byte)]
1
2
3
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

No branches or pull requests

1 participant