[racket-users] typing variable length argument lists

2020-04-10 Thread Hendrik Boom
Trying to convert the following to typed Racket: (define (unique list message . messageargs) ; return the only element of the list, or '() if there is none. ; Produce message if not just one. (if (equal? 1 (length list)) (car list) (begin (apply fprintf (cons anomaly (cons messa

Re: [racket-users] typing variable length argument lists

2020-04-10 Thread Jon Zeppieri
(define (unique [list : (Listof Any)] [message : String] . [messageargs : Any *]) ; return the only element of the list, or '() if there is none. ; Produce message if not just one. (if (equal? 1 (length list)) (car list) (begin (apply fprintf anomaly message messageargs) (i

Re: [racket-users] typing variable length argument lists

2020-04-11 Thread Hendrik Boom
On Fri, Apr 10, 2020 at 08:18:38PM -0400, Jon Zeppieri wrote: > (define (unique [list : (Listof Any)] [message : String] . > [messageargs : Any *]) > ; return the only element of the list, or '() if there is none. > ; Produce message if not just one. > (if (equal? 1 (length list)) (car list)

Re: [racket-users] typing variable length argument lists

2020-04-13 Thread K H
If I understand correctly, the difference to getting the code to type check was: > (apply fprintf (cons anomaly (cons message messageargs))) becomes: >(apply fprintf anomaly message messageargs) Since the documentation explains that the arguments to fprintf are effectively gather

Re: [racket-users] typing variable length argument lists

2020-04-13 Thread Sam Tobin-Hochstadt
The change makes a difference because Typed Racket's type inference for `cons` is producing a less-accurate answer than it could. When it sees arguments of type `String` and `(Listof Any)`, it decides that the result is a `(Listof Any)` instead of a `(Pairof String (Listof Any))`. If you add (exce

Re: [racket-users] typing variable length argument lists

2020-04-13 Thread K H
Thanks Sam, for the explanation. I was thinking that some information was lacking to the type inference system, and it helps to see the annotation incantations necessary to fill in the gap. Cheers, Kieron. On Mon, Apr 13, 2020 at 1:32 PM Sam Tobin-Hochstadt wrote: > The change makes a differe