[plt-scheme] match for Promise
Probably its a good idea to have an example for require/typed in docs.
----- Original Message -----
From: krhari at ccs.neu.edu
To: "Matthias Felleisen" <matthias at ccs.neu.edu>
Cc: "David Herman" <dherman at ccs.neu.edu>, "plt-scheme List" <plt-scheme at list.cs.brown.edu>, krhari at ccs.neu.edu
Sent: Sunday, February 28, 2010 6:58:01 PM GMT -05:00 US/Canada Eastern
Subject: Re: [plt-scheme] match for Promise
I was almost there.
When I did just this,
(require/typed scheme/promise)
I don't know why, but it threw an error on "delay" being unbound.
So I did this.
(require/typed scheme/promise ([promise? (All (A) (A -> Boolean))]))
An extra pair of parans wasted 20 minutes of my time and I did not see your mail.
Thanks its working now.
Hari
----- Original Message -----
From: "Matthias Felleisen" <matthias at ccs.neu.edu>
To: krhari at ccs.neu.edu
Cc: "David Herman" <dherman at ccs.neu.edu>, "plt-scheme List" <plt-scheme at list.cs.brown.edu>
Sent: Sunday, February 28, 2010 6:29:17 PM GMT -05:00 US/Canada Eastern
Subject: Re: [plt-scheme] match for Promise
#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