[racket] users Digest, Vol 109, Issue 60
Please take me off the list
Thanks
On Fri, Sep 26, 2014 at 2:20 PM, <users-request at racket-lang.org> wrote:
> Send users mailing list submissions to
> users at racket-lang.org
>
> 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
> users-request at racket-lang.org
>
> You can reach the person managing the list at
> users-owner at racket-lang.org
>
> 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. Tricky case of occurrence typing in Typed Racket (Konrad Hinsen)
> 2. Re: Tricky case of occurrence typing in Typed Racket (Andrew Kent)
> 3. Re: Tricky case of occurrence typing in Typed Racket
> (Konrad Hinsen)
> 4. Re: Tricky case of occurrence typing in Typed Racket (Andrew Kent)
> 5. Re: ANN: DOS, Delimited-continuation-based Operating-system
> Simulator (Michael Bradley, Jr.)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 26 Sep 2014 18:07:19 +0200
> From: Konrad Hinsen <konrad.hinsen at fastmail.net>
> To: users at racket-lang.org
> Subject: [racket] Tricky case of occurrence typing in Typed Racket
> Message-ID:
> <21541.36663.168649.25871 at Konrad-Hinsens-MacBook-Pro-2.local>
> Content-Type: text/plain; charset=us-ascii
>
> Hi everyone,
>
> I am trying to convince Typed Racket that after a run-time check on
> some list, its elements are all of a given type. This is just like
> occurrence typing based on a predicate, except that my predicate
> is more complicated.
>
> My first attempt was this:
>
>
> #lang typed/racket
>
> (struct: foo ())
> (struct: bar ())
> (define-type FooOrBar (U foo bar))
>
> (: f-bar (-> (Listof bar) Void))
> (define (f-bar xs)
> (void))
>
> (: f-mixed (-> (Listof FooOrBar) Void))
> (define (f-mixed xs)
> (void))
>
> (: f (-> (Listof FooOrBar) Void))
> (define (f xs)
> (if (for/and : Boolean ([x xs]) (bar? x))
> (f-bar xs) ; contains only bars
> (f-mixed xs) ; may contain foos as well
> ))
>
> This yields a type error:
>
> ; /Users/hinsen/projects/racket/foobar.rkt:18:13: Type Checker: type mismatch
> ; expected: (Listof bar)
> ; given: (Listof FooOrBar)
> ; in: xs
>
> After reading section 5 of the Typed Racket Guide, in particular section
> 5.2 entitled "Filters and Predicates", I thought I could simply define my
> own predicate with a type annotation:
>
> #lang typed/racket
>
> (struct: foo ())
> (struct: bar ())
> (define-type FooOrBar (U foo bar))
>
> (: f-bar (-> (Listof bar) Void))
> (define (f-bar xs)
> (void))
>
> (: f-mixed (-> (Listof FooOrBar) Void))
> (define (f-mixed xs)
> (void))
>
> (: pure-bars? (-> (Listof FooOrBar) Boolean : (Listof bar)))
> (define (pure-bars? xs)
> (for/and : Boolean ([x xs]) (bar? x)))
>
> (: f (-> (Listof FooOrBar) Void))
> (define (f xs)
> (if (pure-bars? xs)
> (f-bar xs) ; contains only bars
> (f-mixed xs) ; may contain foos as well
> ))
>
> But this got me only into more trouble - now I don't even understand the
> error message any more:
>
> ; /Users/hinsen/projects/racket/foobar.rkt:17:2: Type Checker: type mismatch;
> ; mismatch in filter
> ; expected: (((Listof bar) @ xs) | (! (Listof bar) @ xs))
> ; given: (Top | Top)
> ; in: (for/and : Boolean ((x xs)) (bar? x))
>
> Is there a way to do this kind of test?
>
> Konrad.
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 26 Sep 2014 12:12:29 -0400
> From: Andrew Kent <amk.kent at gmail.com>
> To: Konrad Hinsen <konrad.hinsen at fastmail.net>
> Cc: users at racket-lang.org
> Subject: Re: [racket] Tricky case of occurrence typing in Typed Racket
> Message-ID:
> <CAMf1y4JeW-jdYeuJP-0x=U=TJB3tahxqvAmuM3TSbeFvGSAYJg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Will andmap work for you?
>
> (struct: foo ())
> (struct: bar ())
> (define-type FooOrBar (U foo bar))
>
> (: f-bar (-> (Listof bar) Void))
> (define (f-bar xs)
> (void))
>
> (: f-mixed (-> (Listof FooOrBar) Void))
> (define (f-mixed xs)
> (void))
>
> (: f (-> (Listof FooOrBar) Void))
> (define (f xs)
> (if (andmap bar? xs)
> (f-bar xs) ; contains only bars
> (f-mixed xs) ; may contain foos as well
> ))
>
> On Fri, Sep 26, 2014 at 12:07 PM, Konrad Hinsen <konrad.hinsen at fastmail.net>
> wrote:
>
>> Hi everyone,
>>
>> I am trying to convince Typed Racket that after a run-time check on
>> some list, its elements are all of a given type. This is just like
>> occurrence typing based on a predicate, except that my predicate
>> is more complicated.
>>
>> My first attempt was this:
>>
>>
>> #lang typed/racket
>>
>> (struct: foo ())
>> (struct: bar ())
>> (define-type FooOrBar (U foo bar))
>>
>> (: f-bar (-> (Listof bar) Void))
>> (define (f-bar xs)
>> (void))
>>
>> (: f-mixed (-> (Listof FooOrBar) Void))
>> (define (f-mixed xs)
>> (void))
>>
>> (: f (-> (Listof FooOrBar) Void))
>> (define (f xs)
>> (if (for/and : Boolean ([x xs]) (bar? x))
>> (f-bar xs) ; contains only bars
>> (f-mixed xs) ; may contain foos as well
>> ))
>>
>> This yields a type error:
>>
>> ; /Users/hinsen/projects/racket/foobar.rkt:18:13: Type Checker: type
>> mismatch
>> ; expected: (Listof bar)
>> ; given: (Listof FooOrBar)
>> ; in: xs
>>
>> After reading section 5 of the Typed Racket Guide, in particular section
>> 5.2 entitled "Filters and Predicates", I thought I could simply define my
>> own predicate with a type annotation:
>>
>> #lang typed/racket
>>
>> (struct: foo ())
>> (struct: bar ())
>> (define-type FooOrBar (U foo bar))
>>
>> (: f-bar (-> (Listof bar) Void))
>> (define (f-bar xs)
>> (void))
>>
>> (: f-mixed (-> (Listof FooOrBar) Void))
>> (define (f-mixed xs)
>> (void))
>>
>> (: pure-bars? (-> (Listof FooOrBar) Boolean : (Listof bar)))
>> (define (pure-bars? xs)
>> (for/and : Boolean ([x xs]) (bar? x)))
>>
>> (: f (-> (Listof FooOrBar) Void))
>> (define (f xs)
>> (if (pure-bars? xs)
>> (f-bar xs) ; contains only bars
>> (f-mixed xs) ; may contain foos as well
>> ))
>>
>> But this got me only into more trouble - now I don't even understand the
>> error message any more:
>>
>> ; /Users/hinsen/projects/racket/foobar.rkt:17:2: Type Checker: type
>> mismatch;
>> ; mismatch in filter
>> ; expected: (((Listof bar) @ xs) | (! (Listof bar) @ xs))
>> ; given: (Top | Top)
>> ; in: (for/and : Boolean ((x xs)) (bar? x))
>>
>> Is there a way to do this kind of test?
>>
>> 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/20140926/72332d84/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 26 Sep 2014 18:28:03 +0200
> From: Konrad Hinsen <konrad.hinsen at fastmail.net>
> To: users at racket-lang.org
> Subject: Re: [racket] Tricky case of occurrence typing in Typed Racket
> Message-ID:
> <21541.37907.627925.114871 at Konrad-Hinsens-MacBook-Pro-2.local>
> Content-Type: text/plain; charset=us-ascii
>
> Andrew Kent writes:
>
> > Will andmap work for you?
>
> Interesting... I didn't know about that one.
>
> For my demonstration code, that's indeed a good solution. In my real
> application, the test is more complicated. I need to check all
> elements of a list for conformance to a union type, so I have no
> prefabricated predicate, not even for the elements of my list.
>
> Konrad.
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 26 Sep 2014 12:48:05 -0400
> From: Andrew Kent <amk.kent at gmail.com>
> To: Konrad Hinsen <konrad.hinsen at fastmail.net>
> Cc: users at racket-lang.org
> Subject: Re: [racket] Tricky case of occurrence typing in Typed Racket
> Message-ID:
> <CAMf1y4LenSG_Ti2S_sFeaDXY6Zo_P5nO9C8-RC6q_TNScG4G9w at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Does using andmap with the custom predicates you alluded to for that union
> you mentioned work?
>
> Something like this perhaps?:
>
> #lang typed/racket
>
> (struct: T1 ())
> (struct: T2 ())
> (define-type T1or2 (U T1 T2))
>
> (: T1or2? (-> Any Boolean : T1or2))
> (define (T1or2? a)
> (or (T1? a) (T2? a)))
>
>
> (: listof-T1or2 (-> Any Boolean : (Listof T1or2)))
> (define (listof-T1or2 l)
> (and (list? l) (andmap T1or2? l)))
>
>
>
> On Fri, Sep 26, 2014 at 12:28 PM, Konrad Hinsen <konrad.hinsen at fastmail.net>
> wrote:
>
>> Andrew Kent writes:
>>
>> > Will andmap work for you?
>>
>> Interesting... I didn't know about that one.
>>
>> For my demonstration code, that's indeed a good solution. In my real
>> application, the test is more complicated. I need to check all
>> elements of a list for conformance to a union type, so I have no
>> prefabricated predicate, not even for the elements of my list.
>>
>> 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/20140926/30da28f4/attachment-0001.html>
>
> ------------------------------
>
> Message: 5
> Date: Fri, 26 Sep 2014 18:15:31 +0000 (UTC)
> From: "Michael Bradley, Jr." <michaelsbradleyjr at gmail.com>
> To: users at racket-lang.org
> Subject: Re: [racket] ANN: DOS, Delimited-continuation-based
> Operating-system Simulator
> Message-ID: <loom.20140926T201005-291 at post.gmane.org>
> Content-Type: text/plain; charset=us-ascii
>
> Jay McCarthy <jay.mccarthy at ...> writes:
>
>>
>> I've just released the game architecture library I talked about in
>> part 2 of my RacketCon talk.
>>
>> The big picture of this library is to make World-style programs more
>> compositional by (a) using continuations to hide the internal state
>> (including control state) of components and (b) using environments as
>> a standard monoid-based inter-component communication channel. A
>> monoid is used to ensure that the components can be evaluated in any
>> order. Despite assumptions some have about continuations and pure
>> functional programming, it is incredibly efficient and can run at
>> 60FPS, as demonstrated in get-bonus.
>>
>> You can get it with
>>
>> raco pkg install dos
>>
>> And you can try out the demo with
>>
>> racket -l dos/examples/win
>>
>> The demo source is a bare 39 lines:
>>
>> https://github.com/jeapostrophe/dos/blob/master/dos/examples/win.rkt
>>
>> and I provide the non-DOS version for comparison:
>>
>> https://github.com/jeapostrophe/dos/blob/master/dos/examples/win-long.rkt
>>
>> The core library has a mere 36 lines:
>>
>> https://github.com/jeapostrophe/dos/blob/master/dos/main.rkt
>>
>
>
>
> Hi Jay,
>
> I really enjoyed your talk on get-bonus at RacketCon last weekend, and
> appreciate your sharing DOS with all of us. Also, your presentation at
> Strange Loop 2013 was my first introduction to delimited continuations in
> Racket!
>
> I have benefited from a number of your blog posts in the past, e.g. the one
> on an improved threading macro, and was wondering if you would consider
> doing a write-up on DOS?
>
> Best regards,
>
> --
> Michael Bradley, Jr.
> @michaelsbradley
>
>
>
>
> End of users Digest, Vol 109, Issue 60
> **************************************