index-of + TR ... parametricity problem?

Skip to first unread message

John Clements

Dec 15, 2019, 9:28:05 PM12/15/19
to Racket-Users List, Sam Tobin-Hochstadt
It looks like my quick attempt at importing index-of into TR is running into a problem. Here’s the program I ran:

#lang typed/racket

(require/typed racket/list
[index-of (All (T) ((Listof T) T -> (U False Natural)))])

(index-of '(n s e w) 'n) ;; returns... #f?

In typed/racket/no-check this returns 0, and also in racket (mutatis mutandis).

I thought this might be some kind of parametricity issue, but even when I instantiate index-of at Symbol which should pretty much clear the way for arbitrary equality checking, I still get False.

Am I missing something obvious? Maybe I shouldn’t be running from the November 14 git head any more?

Welcome to DrRacket, version [3m].


Sam Tobin-Hochstadt

Dec 15, 2019, 9:41:58 PM12/15/19
to John Clements, Racket-Users List
Yes, this is because the contract enforces parametericity, which
doesn't allow `index-of` to work the way you'd want.

Instantiating things doesn't help because the contract is based on the
`require/typed`, not on the use site.

Here's a few suggestions:

1. Submit a pull-request to TR to add `index-of`
2. Import `index-of` at a concrete type
3. Use `unsafe-require/typed`
4. Use the third argument to `index-of?`

> --
> 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
> To view this discussion on the web visit

John Clements

Dec 15, 2019, 10:44:47 PM12/15/19
to Sam Tobin-Hochstadt, Racket-Users List
Oh! of course. Makes sense.

If I make a pull request, does that mean I get a pass for wasting my time doing advent of code?

Reply all
Reply to author
0 new messages