I had to instantiate the "map" function explicitly, and couldn't use "cons?" because it returns whether something is a Pair, not a Listof - but the following works:<div><div><br></div><div><font face="'courier new', monospace">(: cars : (All (A) (Listof (Listof A)) -> (Listof A)))</font></div>
<div><font face="'courier new', monospace">(define (cars ls)</font></div><div><font face="'courier new', monospace"> ((inst map A (Listof A)) car (filter (λ (x) (not (empty? x))) ls)))</font></div><div><br>
</div><div><div><font face="'courier new', monospace">> (cars (list (list 1 2 3 4) (list 6 2 3 4)))</font></div><div><font face="'courier new', monospace">- : (Listof Positive-Byte)</font></div><div><font face="'courier new', monospace">'(1 6)</font></div>
</div><div><br><div class="gmail_quote">On Wed, Apr 4, 2012 at 4:17 PM, Eric Tanter <span dir="ltr"><<a href="mailto:etanter@dcc.uchile.cl">etanter@dcc.uchile.cl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Is there a way to get this to typecheck?<br>
<br>
(: cars : (All (A) (Listof (Listof A)) -> (Listof A)))<br>
(define (cars ls)<br>
(map car (filter cons? ls)))<br>
<br>
By looking at the error, it seems the problem is that it is impossible to map car on a list of lists:<br>
> (map car '((1)))<br>
Type Checker: Polymorphic function map could not be applied to arguments...<br>
<br>
<br>
Thanks,<br>
<br>
-- Éric<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div><br></div></div>