[plt-scheme] Typed Scheme
On 5/25/07, Matthew Swank <akopa.gmane.poster at gmail.com> wrote:
>
> Could someone post an example using the (All (v ...) t) construct.
Here's a simple example:
(define: simple-map : (All (a) ((a -> a) (Listof a) -> (Listof a)))
(plambda: (a) ([f : (a -> a)] [l : (Listof a)])
(cond [(null? l) null]
[else (cons (f (car l))
(map f (cdr l)))])))
(simple-map (lambda: ([x : Number]) (+ x 1)) '(1 2 3))
However, this can be more concisely written as follows:
(pdefine: (a) (simple-map [f : (a -> a)] [l : (Listof a)]) : (Listof a)
(cond [(null? l) null]
[else (cons (f (car l))
(map f (cdr l)))]))
where pdefine: abbreviates all of the boilerplate, including the use
of (All ...).
Thanks,
--
sam th
samth at ccs.neu.edu