[racket-dev] Motivation for polymorphic opaque types

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sun Jan 6 15:40:14 EST 2013

On Sun, Jan 6, 2013 at 3:23 PM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> On Sun, Jan 6, 2013 at 2:18 PM, Sam Tobin-Hochstadt <samth at ccs.neu.edu>
> wrote:
>>
>> > The boundaries have the information; that's how the contracts got
>> > inserted
>> > in the first place.
>>
>> No, the contracts are parametric contracts using `parametric->/c`, and
>> thus don't have any information about the types used at all.
>
>
> I don't see why you can't tag them when something at a boundary and then
> check that something at another boundary instead of doing some deep check.

The problem is that I don't know what to tag them *with*.

Consider the following program:

#lang racket

(struct kons (a d))
(struct mt ())
(define MT (mt))
(define (FST v)
  (when (eq? MT v) (error 'empty))
  (kons-a v))
(define (RST v)
  (when (eq? MT v) (error 'empty))
  (kons-d v))
(define (LST . x)
  (if (empty? x)
      MT
      (kons (first x) (apply LST (rest x)))))
(define (LST/C elem/c)
  (define C (recursive-contract
             (or/c (λ (v) (eq? v MT))
                   (struct/c kons elem/c C))))
  C)
(provide/contract
 [LST (parametric->/c (A) (->* () #:rest A (LST/C A)))]
 [FST (parametric->/c (A) (-> (LST/C A) A))]
 [RST (parametric->/c (A) (-> (LST/C A) (LST/C A)))])

This is the essence of Neil's polymorphic list program, as implemented
by Typed Racket. I don't know how to change those contracts to not be
really expensive, because I can't pick the instantiation of A at
runtime to tag the structure instances with.

Sam


Posted on the dev mailing list.