[racket] [Typed Racket] mapping car

From: Luke Vilnis (lvilnis at gmail.com)
Date: Wed Apr 4 15:45:17 EDT 2012

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:

(: cars : (All (A) (Listof (Listof A)) -> (Listof A)))
(define (cars ls)
 ((inst map A (Listof A)) car (filter (λ (x) (not (empty? x))) ls)))

> (cars (list (list 1 2 3 4) (list 6 2 3 4)))
- : (Listof Positive-Byte)
'(1 6)

On Wed, Apr 4, 2012 at 4:17 PM, Eric Tanter <etanter at dcc.uchile.cl> wrote:

> Hi,
>
> Is there a way to get this to typecheck?
>
> (: cars : (All (A) (Listof (Listof A)) -> (Listof A)))
> (define (cars ls)
>  (map car (filter cons? ls)))
>
> By looking at the error, it seems the problem is that it is impossible to
> map car on a list of lists:
> > (map car '((1)))
> Type Checker: Polymorphic function map could not be applied to arguments...
>
>
> Thanks,
>
> -- Éric
>
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120404/a8f891b2/attachment.html>

Posted on the users mailing list.