[racket] TR - Back patching avoidance in struct:

From: Ray Racine (ray.racine at gmail.com)
Date: Tue Aug 28 12:32:31 EDT 2012

Is there a current cleverness in TR that allows for typesafe avoidance of
back patching a self referential structure.

Say one wants to construct a TOP-NODE where the parent field is itself.  I
know I could make parent : (Option Node) and back patch with a set!.  But
could one do better.

The below type checks but of course fails on execution.  However some sort
special post structure construction asserting "defined-ness" of the parent
field triggered as a post operation after (atomic) structure creation
assertion would get one there.

#lang typed/racket/base

(struct: Node ([parent : Node]))

(: TOP-NODE Node )
(define TOP-NODE
  (letrec: ((self : Node (Node (assert self Node?))))
    self))

;;;;;;;;;;

 Anyway, just a random thought on a coffee break.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120828/fe53a1fd/attachment.html>

Posted on the users mailing list.