[plt-scheme] Typed Scheme

From: Sam TH (samth at ccs.neu.edu)
Date: Sat May 26 07:57:12 EDT 2007

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


Posted on the users mailing list.