[plt-scheme] Re: Typed Scheme

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun May 27 07:59:09 EDT 2007

That's not really a case-lambda at all, is it? case-lambda dispatches
on the number of arguments at a call-site, not the type of the
argument.

Robby

On 5/26/07, Matthew Swank <akopa.gmane.poster at gmail.com> wrote:
> On Sat, 26 May 2007 07:57:12 -0400, Sam TH wrote:
>
> > 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 ...).
> >
>
> This is a silly example:
>
> (define: x-or-nil : (case-lambda (number -> number)
>                                  ((Listof number) -> (Listof number)))
>     (case-lambda:
>       (((x : number)) x)
>       (((x : (Listof number))) ())))
>
> but is there a more compact way to define case-lambdas?
>
> Thanks again,
>
> Matt
> --
> "You do not really understand something unless you
>  can explain it to your grandmother." - Albert Einstein.
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.