<div>Sorry I was not clear. I want to specify a function like map, where the arity of the mapping function argument is dependent on the rest of the arguments to map. Your solution does that. But I also want to specify the return type of the mapping function. I did not see a way to describe the mapping function return type that does not also restrict the way I can describe its arguments.
</div>
<div> </div>
<div>More concretly, consider:</div>
<div>
<p>(define (build/join-strings mapping-f separator . lsts)<br> (foldl (lambda (st so-far)<br> (format "~a~a~a"<br> so-far<br> (if (equal? so-far "")
<br> ""<br> separator)<br> st))<br> ""<br> (apply map (cons mapping-f lsts)))))</p>
<p>I want to state that mapping-f has the same arity has the rest arguments to build/join-strings which your solution does, but I also want to say that mapping-f must return a string.</p>
<p>-pp</p>
<p> </p></div>
<div> </div>
<div><br><br> </div>
<div><span class="gmail_quote">On 1/24/06, <b class="gmail_sendername">Robby Findler</b> <<a href="mailto:robby@cs.uchicago.edu">robby@cs.uchicago.edu</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">You have to pin down the arity enough that users of your function know<br>what the legal argument lengths are. (Is that what you're asking?)
<br><br>Robby<br><br>At Mon, 23 Jan 2006 23:58:08 +0000, pedro pinto wrote:<br>> One more question, how would I go about saying something about the return<br>> type of proc/func? From my understanding of the docs I need to write a
<br>> function contract, as opposed to what I think is a flat-contract like<br>> arity-matches-lists, but I did not see a way to write one that does not also<br>> pin down the arity.<br>><br>> -pp<br>><br>
><br>><br>> > On 1/23/06, Robby Findler <<a href="mailto:robby@cs.uchicago.edu">robby@cs.uchicago.edu</a>> wrote:<br>> > ><br>> > > You have to use the more complex combinators to express that. Here's
<br>> > > how ->r can be used to express map's contract:<br>> > ><br>> > > (module map-c mzscheme<br>> > > (require (lib "contract.ss"))<br>> > ><br>> > > (define map-c map)
<br>> > ><br>> > > (provide/contract<br>> > > [map-c<br>> > > (->r ([func<br>> > > (and/c<br>> > > procedure?<br>> > > (let ([arity-matches-lists
<br>> > > (ë (f)<br>> > > (procedure-arity-includes? f (+ 1 (length<br>> > > rest-args))))])<br>> > > arity-matches-lists))]<br>> > > [lst-one (listof any/c)])
<br>> > > rest-args<br>> > > (and/c (listof (listof any/c))<br>> > > (let ([same-length-lists (ë (x) (apply equal? (length<br>> > > lst-one) (map length x)))])
<br>> > > same-length-lists))<br>> > > (listof any/c))]))<br>> > ><br>> > > (require map-c)<br>> > ><br>> > > (define (print-msg exn)<br>> > > (display (exn-message exn))
<br>> > > (newline))<br>> > ><br>> > > (map-c (lambda (x y) x) (list 1 2 3) (list 4 5 6))<br>> > > (with-handlers ([values print-msg])<br>> > > (map-c (lambda (x) x) (list 1 2 3) (list 4 5 6)))
<br>> > > (with-handlers ([values print-msg])<br>> > > (map-c (lambda (x y) x) (list 1 2 3) (list 4 5 6 7)))<br>> > ><br>> > > At Mon, 23 Jan 2006 19:49:34 +0000, pedro pinto wrote:<br>
> > > > Hi there,<br>> > > ><br>> > > > I just started fumbling around with contracts and I was trying to<br>> > > write a<br>> > > > contract for a function similar to map:
<br>> > > ><br>> > > > map proc clist1 clist2 ... -> list<br>> > > ><br>> > > > Is there a way to say that proc is a procedure whose arity should<br>> > > match the
<br>> > > > number of clist arguments?<br>> > > ><br>> > > > TIA,<br>> > > > -pp<br>> > > > _________________________________________________<br>> > > > For list-related administrative tasks:
<br>> > > > <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>> > ><br>> ><br>> ><br></blockquote></div><br>