[plt-scheme] Re: Typed Scheme

From: Sam TH (samth at ccs.neu.edu)
Date: Sun May 27 00:35:37 EDT 2007

Matthew-

Unfortunately not.  If you have a suggestion for a more compact
syntax, I'd be happy to consider it.

Also, note that your function always calls the first case, because
that's how the underlying case-lambda form works.  The fact that your
code typechecks is actually a bug in the typechecker - that function
has type (Number -> Number).  The next release of the package will fix
this (among other) bug.

sam th

On 5/27/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
>


-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.