[racket] What am I doing wrong in this typed racket program?

26 views
Skip to first unread message

Tony Garnock-Jones

unread,
Sep 18, 2012, 5:44:44 PM9/18/12
to Racket Users
Hi all,

What could I be doing wrong here?

#lang typed/racket
(provide (struct-out foo))
(struct: foo ([bar : (Setof Any)]))

Racket 5.3.0.24 complains about it ("racket problem.rkt"):

set/c: contract violation
expected: chaperone-contract?
given: #<make-contract>
context...:
/Users/tonyg/src/racket-typed-matrix/problem.rkt: [running body]

The complaint vanishes if I comment out the provide, remove the bar
field, or change the bar field's type to Any/Integer/etc.

Tony
____________________
Racket Users list:
http://lists.racket-lang.org/users

Sam Tobin-Hochstadt

unread,
Sep 18, 2012, 5:53:38 PM9/18/12
to Tony Garnock-Jones, Racket Users
The problem here is that `Any` is a special contract which isn't a
"chaperone contract", and `set/c` requires chaperone contracts.

It's not obvious to me if this can be detected statically, but you can
work around this by changing `Any` to some other type.

Sam
--
sam th
sa...@ccs.neu.edu

Robby Findler

unread,
Sep 18, 2012, 5:57:13 PM9/18/12
to Sam Tobin-Hochstadt, Racket Users
Are you saying it is reasonable that a typed racket program should
produce contract constructor errors like that?

Robby

Sam Tobin-Hochstadt

unread,
Sep 18, 2012, 6:00:24 PM9/18/12
to Robby Findler, Racket Users
I'm saying that I don't at the moment know how to avoid giving this
error, given the current behavior of `set/c`.

Robby Findler

unread,
Sep 18, 2012, 6:23:47 PM9/18/12
to Sam Tobin-Hochstadt, Racket Users
Can you explain more? Surely TR must know what "Setof" is, because it
translated it to "set/c" and surely it must know what "Any" is, since
it turned it into some other contract. That seems like enough
information to me.

Robby

Ryan Culpepper

unread,
Sep 18, 2012, 6:28:11 PM9/18/12
to Sam Tobin-Hochstadt, Racket Users, Robby Findler
Typed Racket should raise an error saying something like "(Setof Any)
cannot be translated to a contract". Then elaborate in the docs where
you discuss interaction with untyped code about what types cannot be
converted to contracts and maybe why.

Ryan

Matthias Felleisen

unread,
Sep 18, 2012, 8:38:33 PM9/18/12
to Ryan Culpepper, Racket Users, Robby Findler, Sam Tobin-Hochstadt

+1

A flavor of this problem has come up repeatedly, and it will come up again. We need some fix.

Eric Dobson

unread,
Sep 18, 2012, 8:48:54 PM9/18/12
to Matthias Felleisen, Racket Users, Robby Findler, Sam Tobin-Hochstadt
I have done some work in this area, and my patches are currently
sitting on github waiting for comments. (And also some cleanup by me).

I believe that the current version in my pull request will give a
static error here.

https://github.com/plt/racket/pull/139

Tony Garnock-Jones

unread,
Sep 19, 2012, 2:19:24 PM9/19/12
to Sam Tobin-Hochstadt, Racket Users
On 09/18/2012 05:53 PM, Sam Tobin-Hochstadt wrote:
> It's not obvious to me if this can be detected statically, but you can
> work around this by changing `Any` to some other type.

Thanks for the explanation.

It took me a long time to narrow it down to the minimal example I gave
(starting from a hundred lines or so of type definitions). It took me a
long time to see the "set/c" as the vital clue it was, and there's no
mention of "Any" anywhere. Having a line number would have helped immensely.

I was also not thinking in terms of typed-to-untyped interaction---I was
thinking "oh, this will provide the types and the values to other TR
programs"---so the appearance of contracts was sudden and surprising.

Regards,

Matthias Felleisen

unread,
Sep 19, 2012, 2:21:10 PM9/19/12
to Tony Garnock-Jones, Racket Users, Sam Tobin-Hochstadt

Develop in Dr. Watch type errors at bottom.

Sam Tobin-Hochstadt

unread,
Sep 19, 2012, 2:26:00 PM9/19/12
to Robby Findler, Racket Users
Thinking about this further, I think Typed Racket should always know
when chaperone contracts are required, just as it currently checks
when flat contracts are required. So this shouldn't be too hard to
fix.

On Tue, Sep 18, 2012 at 6:23 PM, Robby Findler
Reply all
Reply to author
Forward
0 new messages