[plt-scheme] match for Promise

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Feb 28 18:29:17 EST 2010

#lang typed/scheme

(require scheme/match
         web-server/dispatch/extend)

(require/typed scheme/promise (promise? (Any -> Boolean)))

(define-coercion-match-expander promise promise? force)

(define foo (delay 42))

((inst force Exact-Positive-Integer) foo)

(: bar : ((Promise Integer) -> Integer))
(define (bar prom)
 (match prom
   [(promise x) x]
   [else (error "Unknown" 'bar)]))



On Feb 28, 2010, at 6:07 PM, krhari at ccs.neu.edu wrote:

> With your example, I tried this and it throws an error on promise?. untyped identifier imported blah blah.
> Still trying get it working. Thanks anyways Dave. 
> 
> #lang typed-scheme
> 
> (require scheme/match
>         scheme/promise
>         web-server/dispatch/extend)
> 
> (define-coercion-match-expander promise promise? force)
> 
> (define foo (delay 42))
> 
> (: bar : ((Promise Integer) -> Integer))
> (define (bar prom)
>  (match prom
>    [(promise x) x]
>    [else (error "Unknown" 'bar)]))
> 
> (bar foo) 
> 
> Hari
> 
> 
> ----- Original Message -----
> From: "David Herman" <dherman at ccs.neu.edu>
> To: krhari at ccs.neu.edu
> Cc: "plt-scheme List" <plt-scheme at list.cs.brown.edu>
> Sent: Sunday, February 28, 2010 5:18:30 PM GMT -05:00 US/Canada Eastern
> Subject: Re: [plt-scheme] match for Promise
> 
> Oh-- I've no idea how to make it work with Typed Scheme, though. Sorry,
> 
> Dave
> 
> On Feb 28, 2010, at 2:08 PM, David Herman wrote:
> 
>> A quick implementation:
>> 
>> ;; --
>> #lang scheme/base
>> 
>> (require scheme/match
>>        scheme/promise
>>        web-server/dispatch/extend)
>> 
>> (define-coercion-match-expander promise promise? force)
>> ;; --
>> 
>> Example:
>> 
>>> (define foo
>>   (delay (begin (printf "forced!\n") 42)))
>>> foo
>> #<promise:foo>
>>> (match foo
>>   [(promise x) x])
>> forced!
>> 42
>> 
>> [It seems to me define-coercion-match-expander is useful enough to belong in scheme/match.]
>> 
>> Dave
>> 
>> On Feb 27, 2010, at 1:02 AM, krhari at ccs.neu.edu wrote:
>> 
>>> Hi,
>>> In Typed Scheme, I have a structure which has a field of type 
>>> 
>>> (Promise (Pair A B)).
>>> 
>>> Is it possible to use match for this(for Promise)? 
>>> 
>>> Thanks
>>> Hari
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>> 
> 
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.