Please take me off the list Thanks
On Mon, Sep 29, 2014 at 2:00 PM, <[email protected]> wrote: > Send users mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://lists.racket-lang.org/users/listinfo > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of users digest..." > > > [Racket Users list: > http://lists.racket-lang.org/users ] > > > Today's Topics: > > 1. Cyclic data structures in Typed Racket (Konrad Hinsen) > 2. Re: Cyclic data structures in Typed Racket (Sam Tobin-Hochstadt) > 3. Re: Cyclic data structures in Typed Racket (Konrad Hinsen) > 4. Re: Cyclic data structures in Typed Racket (Sam Tobin-Hochstadt) > 5. Re: Cyclic data structures in Typed Racket (Benjamin Greenman) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 29 Sep 2014 18:10:29 +0200 > From: Konrad Hinsen <[email protected]> > To: [email protected] > Subject: [racket] Cyclic data structures in Typed Racket > Message-ID: > <[email protected]> > Content-Type: text/plain; charset=us-ascii > > Hi everyone, > > I am trying to port code creating a cyclic data structure to Typed > Racket, but notice that this is not as straightforward as I expected. > > Here is the untyped code I start from: > > #lang racket > > (struct foo (x) #:mutable) > (struct bar (x)) > > (define-values (f b) > (shared ([f (foo b)] > [b (bar f)]) > (values f b))) > > (eq? (bar-x b) f) > (eq? (foo-x f) b) > > Switching to Typed Racket and annotating the struct definitions, I get > an error message saying that make-placeholder and placeholder-set! > from racket/base are lacking type annotations. I also get the recommendation > to use require/typed for importing them. OK, let's try: > > #lang typed/racket > > (require/typed racket/base > [#:opaque Placeholder placeholder?] > [make-placeholder (-> Any Placeholder)] > [placeholder-set! (-> Placeholder Any Void)]) > > (struct foo ([x : bar]) #:mutable) > (struct bar ([x : foo])) > > (define-values (f b) > (shared ([f (foo b)] > [b (bar f)]) > (values f b))) > > (eq? (bar-x b) f) > (eq? (foo-x f) b) > > Same error message... which is not really surprising. I suppose typed/racket > already requires racket/base, so my additional require/typed has no effect. > But how can I fix this? I don't see any way to exclude items from > typed/racket. > > Konrad. > > > ------------------------------ > > Message: 2 > Date: Mon, 29 Sep 2014 12:17:29 -0400 > From: Sam Tobin-Hochstadt <[email protected]> > To: Konrad Hinsen <[email protected]> > Cc: users <[email protected]> > Subject: Re: [racket] Cyclic data structures in Typed Racket > Message-ID: > <CAK=HD+Y2x3d1e=caisu9xayyfqrvwm+eht+rg66ydcpeahn...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > I recommend doing the mutation yourself, and not using `shared`. > That's the most obvious solution. > > 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. > > Note also that the types you gave aren't safe -- the way shared uses > placeholders expects particular types for particular ones (this would > result in a contract error at runtime if `shared` used your bindings). > > Sam > > On Mon, Sep 29, 2014 at 12:10 PM, Konrad Hinsen > <[email protected]> wrote: >> Hi everyone, >> >> I am trying to port code creating a cyclic data structure to Typed >> Racket, but notice that this is not as straightforward as I expected. >> >> Here is the untyped code I start from: >> >> #lang racket >> >> (struct foo (x) #:mutable) >> (struct bar (x)) >> >> (define-values (f b) >> (shared ([f (foo b)] >> [b (bar f)]) >> (values f b))) >> >> (eq? (bar-x b) f) >> (eq? (foo-x f) b) >> >> Switching to Typed Racket and annotating the struct definitions, I get >> an error message saying that make-placeholder and placeholder-set! >> from racket/base are lacking type annotations. I also get the recommendation >> to use require/typed for importing them. OK, let's try: >> >> #lang typed/racket >> >> (require/typed racket/base >> [#:opaque Placeholder placeholder?] >> [make-placeholder (-> Any Placeholder)] >> [placeholder-set! (-> Placeholder Any Void)]) >> >> (struct foo ([x : bar]) #:mutable) >> (struct bar ([x : foo])) >> >> (define-values (f b) >> (shared ([f (foo b)] >> [b (bar f)]) >> (values f b))) >> >> (eq? (bar-x b) f) >> (eq? (foo-x f) b) >> >> Same error message... which is not really surprising. I suppose typed/racket >> already requires racket/base, so my additional require/typed has no effect. >> But how can I fix this? I don't see any way to exclude items from >> typed/racket. >> >> Konrad. >> ____________________ >> Racket Users list: >> http://lists.racket-lang.org/users > > > ------------------------------ > > Message: 3 > Date: Mon, 29 Sep 2014 18:33:38 +0200 > From: Konrad Hinsen <[email protected]> > To: Sam Tobin-Hochstadt <[email protected]> > Cc: users <[email protected]> > Subject: Re: [racket] Cyclic data structures in Typed Racket > Message-ID: > <[email protected]> > Content-Type: text/plain; charset=us-ascii > > 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. > > > ------------------------------ > > Message: 4 > Date: Mon, 29 Sep 2014 12:52:25 -0400 > From: Sam Tobin-Hochstadt <[email protected]> > To: Konrad Hinsen <[email protected]> > Cc: users <[email protected]> > Subject: Re: [racket] Cyclic data structures in Typed Racket > Message-ID: > <CAK=hd+ywfnfv-mjqppo9gmoo8u+av7f6ue-4motks_gkvnn...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > 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 > <[email protected]> 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. > > > ------------------------------ > > Message: 5 > Date: Mon, 29 Sep 2014 14:00:12 -0400 > From: Benjamin Greenman <[email protected]> > To: Sam Tobin-Hochstadt <[email protected]> > Cc: users <[email protected]> > Subject: Re: [racket] Cyclic data structures in Typed Racket > Message-ID: > <CAAtAoRpHmBjH4FW1BwSOoDh41=m=bzt2q4wz9xdq+wfj8rs...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > To be sure: Is there any TR analog to this OCaml code, initializing a > cyclic, 3-element list? I've tried using letrec in TR, but the typechecker > yells at me even if I annotate the a,b,c,d. > > # type 'a mylist = Nil | Cons of 'a * 'a mylist;; > type 'a mylist = Nil | Cons of 'a * 'a mylist > # let mylist = > let rec a = Cons(1, b) > and b = Cons(2, c) > and c = Cons(3, d) > and d = Cons(4, a) in > a;; > val mylist : int mylist = Cons (1, Cons (2, Cons (3, Cons (4, <cycle>)))) > > On Mon, Sep 29, 2014 at 12:52 PM, Sam Tobin-Hochstadt <[email protected]> > 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 >> <[email protected]> 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 >> > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://lists.racket-lang.org/users/archive/attachments/20140929/152cdf29/attachment.html> > > End of users Digest, Vol 109, Issue 77 > ************************************** ____________________ Racket Users list: http://lists.racket-lang.org/users

