[racket] [Typed Racket] mapping car

From: Eric Tanter (etanter at dcc.uchile.cl)
Date: Thu Apr 5 20:47:11 EDT 2012

Thanks!

-- Éric


On Apr 4, 2012, at 3:45 PM, Luke Vilnis wrote:

> 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
> 



Posted on the users mailing list.