[racket] Is this a bug in contracts?
On Jan 16, 2013, at 7:39 PM, Harry Spier wrote:
> On Mon, Jan 14, 2013 at 9:27 AM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> And Harry, do define certain contracts separately, e.g.,
>>
>> (define shish/c (is-a?/c shish-D%))
>>
>
> If my class has a field of the same class is there a way to do that?
>
> I.e. both case 1 and case 2 fail on undefined identifier
> Case 1
> #lang racket
> (define pizza-D%/c (is-a?/c pizza-D%))
>
> (define/contract pizza-D%
> (class/c [init-field (p pizza-D%/c)])
> (class pizza-D% (super-new)
> (init-field p)))
>
> Case 2
> #lang racket
> (define/contract pizza-D%
> (class/c [init-field (p pizza-D%/c)])
> (class pizza-D% (super-new)
> (init-field p)))
>
> (define pizza-D%/c (is-a?/c pizza-D%))
First, you mistakenly have the class inherit from itself. You want object% in the super-class position in both cases.
Second, you don't get to formulate contracts like that. We have flat-rec-contracts but a class contract is a higher-order contract because a class is like a function.
Contracts and types are incomparable in expressiveness.