Issue with define-type and typed classes

46 views
Skip to first unread message

hashim muqtadir

unread,
Mar 5, 2020, 3:49:48 AM3/5/20
to Racket Users

Lines 51 through 55 say:

(define-type (Func<%> A)
  (BaseFunc<%> A FuncAnyParam))

(define-type BoolFunc<%> (Func<%> BooleanColumn))
(define-type AnyFunc<%> (Func<%> ColIdent))


And this used to work on older versions of racket, say Racket BC 7.4

But on Racket CS 7.6, I get an error on this line:
(define-type AnyFunc<%> (Func<%> ColIdent))

Even though (a) it doesn't throw an error on the line before it, and
(b) replacing it with (define-type AnyFunc<%> (BaseFunc<%> ColIdent FuncAnyParam))
works.

I thought the way define-type works is that

(Func<%> ColIdent)
would expand into
(BaseFunc<%> ColIdent FuncAnyParam)

I've had similar problems with define-type previously where I'd think it would just expand
by substituting the parameter but it doesn't seem to really do that. I don't have any
trivial example to show, though. Fiddling around eventually gets it to work.

I'd really appreciate some help as to how to think about what define-type does in my head.

Ben Greenman

unread,
Mar 31, 2020, 8:01:44 PM3/31/20
to Racket Users
On 3/5/20, hashim muqtadir <hashim....@gmail.com> wrote:
> So I have this file, found here:
> https://gitlab.com/hashimmm/remap/-/blob/3682db9fff3bc5007833e07bf9a9ed6e8e0170a9/private/tables.rkt
>
> Lines 51 through 55 say:
>
> (define-type (Func<%> A) (BaseFunc<%> A FuncAnyParam))(define-type
> BoolFunc<%> (Func<%> BooleanColumn))(define-type AnyFunc<%> (Func<%>
> ColIdent))
>
> And this used to work on older versions of racket, say Racket BC 7.4
>
> But on Racket CS 7.6, I get an error on this line:
> (define-type AnyFunc<%> (Func<%> ColIdent))
>
> Even though (a) it doesn't throw an error on the line before it, and
> (b) replacing it with (define-type AnyFunc<%> (BaseFunc<%> ColIdent
> FuncAnyParam))
> works.
>
> I thought the way define-type works is that
> (Func<%> ColIdent)
> would expand into (BaseFunc<%> ColIdent FuncAnyParam)
>
> I've had similar problems with define-type previously where I'd think it
> would just expand
> by substituting the parameter but it doesn't seem to really do that. I don't
> have any
> trivial example to show, though. Fiddling around eventually gets it to
> work.
>
> I'd really appreciate some help as to how to think about what define-type
> does in my head.
>

That code should work. There's a bug somewhere, either TR or deeper.

I am thinking its deeper because the code sometimes compiles.

1. When I first tried `raco pkg install remap` (using a current CS), it worked
2. Then I tried compiling with BC 7.6 and CS 7.6. BC succeeded and CS failed.
3. Later, I saw 2 consecutive runs of CS fail and succeed:

```
(20:02)% rm -r compiled

(20:02)% /Applications/RacketCS-v7.6/bin/raco make -v tables.rkt
"tables.rkt":
making #<path:/Users/ben/code/racket/fork/extra-pkgs/remap/private/tables.rkt>
/Users/ben/code/racket/fork/extra-pkgs/remap/private/tables.rkt:59:3:
Type Checker: parse error in type;
expected a class type for #:implements clause
given: (Opaque Func<%>)
in: (Class #:implements BoolFunc<%>)
compilation context...:
/Users/ben/code/racket/fork/extra-pkgs/remap/private/tables.rkt
context...:
do-raise-syntax-error
winder-dummy
.../private/parse-type.rkt:1234:0: merge-with-parent-type
.../private/parse-type.rkt:1364:14: for-loop
.../private/parse.rkt:852:26
.../private/runtime.rkt:80:24: temp5975
.../env/type-alias-helper.rkt:230:4: for-loop
.../env/type-alias-helper.rkt:101:0: register-all-type-aliases
.../typecheck/tc-toplevel.rkt:359:0: type-check
.../typecheck/tc-toplevel.rkt:602:0: tc-module
.../typed-racket/tc-setup.rkt:96:12
winder-dummy
.../typed-racket/typed-racket.rkt:23:4
call-in-empty-metacontinuation-frame
apply-transformer
dispatch-transformer

(1:20:02)% rm -r compiled
rm: compiled: No such file or directory

(1:20:02)% /Applications/RacketCS-v7.6/bin/raco make -v tables.rkt
"tables.rkt":
making #<path:/Users/ben/code/racket/fork/extra-pkgs/remap/private/tables.rkt>
[output to "compiled/tables_rkt.zo"]
```

hashim muqtadir

unread,
Apr 2, 2020, 3:43:40 AM4/2/20
to Racket Users

I am thinking its deeper because the code sometimes compiles.

Yes, this happens with me too. I haven't tried it using raco but in DrRacket, while I
was fiddling around with these classes, it would sometimes fail to compile, but
I just used to erase what I wrote, and then re-write, and it would work.

Once compiled it seemed to work fine.

But I believe they're separate problems.

I'll try to be more diligent about reporting issues with typed classes next time. I used to run into
problems similar to what I reported in this thread previously, too, on whatever version of Racket
was out a year or two ago, but I was throwing away and rewriting code quickly and it
was hard to come up with minimal examples at the time.

This one reproduced very reliably and I wasn't really making big changes so I was able to
report easily.

Sam Tobin-Hochstadt

unread,
Apr 2, 2020, 8:21:28 AM4/2/20
to hashim muqtadir, Racket Users
When this happens, it's usually a bug in Typed Racket caused by depending on hash table ordering, so it would be great to find and fix it. 

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/b3199035-27c9-4549-890d-0a4aac48d924%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages