RACKET: Require a pair type function

131 views Asked by At

I'm making a program in the plai-typed language, however I want to use the functions 'car' and 'cdr'

 (require (typed-in racket
               (car : (pair -> any/c))
               (cdr : (pair -> any/c))))

However it gives me the error pair:bad type

Why is this? What 'type' should I fill in instead of 'pair' since in the documentation it says that the input for both function is a pair.

I tried typing 'Pair' 'pair' 'Pairs' 'pairs' however none work

1

There are 1 answers

0
Sorawee Porncharoenwase On BEST ANSWER

I think you want (... * ...)

(require (typed-in racket
                   (car : (('a * 'b) -> 'a))
                   (cdr : (('a * 'b) -> 'b))
                   (cons : ('a 'b -> ('a * 'b)))))

Then:

> (cons 1 2)
- (number * number)
'(1 . 2)
> (car (cons 1 2))
- number
1

Valid types are listed in https://docs.racket-lang.org/plai-typed/index.html#%28part._.Types%29. any/c or pair is not valid one.

Also note that there're pair, fst, snd in plai-typed.