[racket] Little Schemer, lat?

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Thu Jan 8 18:23:32 EST 2015

The `List` type constructor is for lists of specific length. E.g.
`(List Integer Integer Integer)`, which is the type of lists of length 3
containing only integers.

The `Listof` type constructor is what you want here. It represents
homogeneous lists of unknown length.

Vincent




At Fri, 9 Jan 2015 10:18:25 +1100,
Daniel Prager wrote:
> 
> I was surprised that *cdr* upsets the type-checker? How to fix?
> 
> #lang typed/racket
> 
> (: atom? (-> Any Boolean))
> (define (atom? a)
>   (or (symbol? a) (boolean? a) (number? a) (string? a)))
> 
> (: lat? (-> (List Any) Boolean))
> (define (lat? l)
>   (cond
>     [(null? l) #t]
>     [(atom? (car l)) (lat? (cdr l))]
>     [else #f]))
> 
> 
> Type Checker: Polymorphic function `cdr' could not be applied to arguments:
> Types: (Pairof a b) -> (b : ((! False @ (cdr) (0 0)) | (False @ (cdr) (0
> 0))) : (cdr (0 0)))
>        (Listof a) -> (Listof a)
> Arguments: (List Any)
> Expected result: (List Any)
>  in: (cdr l)
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.