[racket] Cyclic data structures in Typed Racket

From: Benjamin Greenman (blg59 at cornell.edu)
Date: Mon Sep 29 16:32:19 EDT 2014

Could Andrew Myer's work on masked types (to eliminate nulls for object
initialization) be relevant?
http://www.cs.cornell.edu/Projects/jmask/

On Mon, Sep 29, 2014 at 3:30 PM, Matthias Felleisen <matthias at ccs.neu.edu>
wrote:

>
> I guess the real problem is to create suitable default values so
> that the pass the type checker or to figure out a cast that forces
> TR to accept some other value as the default value (and making sure
> you never use the object).
>
> Undefined not completely solved. Argh. -- Matthias
>
>
>
>
>
> On Sep 29, 2014, at 12:52 PM, Sam Tobin-Hochstadt <samth at cs.indiana.edu>
> wrote:
>
> > Ah, if you want to create truly cyclic structure with no base case
> > like this, then you'll have to do more work. Either you'll need to
> > expand the type of the `x` field in `foo` to allow an initial value,
> > or you'll need to create a dummy `foo` with that extended type, and
> > then copy the cyclic data once you've created it to a new version of
> > `foo`, using hash tables to track cycles. That's basically how
> > `shared` works, although I haven't tried implementing it in TR and it
> > might not be possible.
> >
> > Sam
> >
> > On Mon, Sep 29, 2014 at 12:33 PM, Konrad Hinsen
> > <konrad.hinsen at fastmail.net> wrote:
> >> Sam Tobin-Hochstadt writes:
> >>
> >>> I recommend doing the mutation yourself, and not using `shared`.
> >>> That's the most obvious solution.
> >>
> >> Not for me, unfortunately, but probably I am missing something
> >> obvious.
> >>
> >> Here's explicit mutation in untyped Racket:
> >>
> >>   #lang racket
> >>
> >>   (struct foo (x) #:mutable)
> >>   (struct bar (x))
> >>
> >>   (define f (foo (void)))
> >>   (define b (bar f))
> >>   (set-foo-x! f b)
> >>
> >>   (eq? (bar-x b) f)
> >>   (eq? (foo-x f) b)
> >>
> >> That works fine. Moving to Typed Racket, this is rejected by the type
> >> checker because (void) is of type Void.  Since I need a bar to make a
> >> foo and a foo to make a bar, I don't see how I can ever initialize my
> >> foo structure.
> >>
> >>> The reason that your `require/typed` doesn't work is that it creates
> >>> new versions of the placeholder functions, but those aren't the ones
> >>> that `shared` uses internally, so Typed Racket doesn't use the types
> >>> you've given.
> >>
> >> That makes sense, thanks for the explanation!
> >>
> >> Konrad.
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140929/0ff9b0cf/attachment-0001.html>

Posted on the users mailing list.