1

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

Shawn
  • 47,241
  • 3
  • 26
  • 60

1 Answers1

1

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.

Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28