问题
I'm using pl
in racket: https://pl.barzilay.org/
The download can be found here: http://pl.barzilay.org/pl.plt
( : f1 : -> (Pairof Symbol String))
(define (f1)
(cons 'wwww "aaa"))
Error:
Type Checker: Polymorphic function `cons' could not be applied to arguments:
Argument 1:
Expected: a
Given: 'wwww
Argument 2:
Expected: (Listof a)
Given: String
Result type: (Listof a)
Expected result: (Pairof Symbol String)
in: (cons (quote wwww) "aaa")
What I did wrong and how can I fix it?
回答1:
The #lang pl
language that I use in my class is a variant of Typed
Racket. One of the changes it has is that cons
has a more restricted
type (as you've seen) which allows it to only construct proper lists.
(As a sidenote, the reason there is no formal documentation is that this language is intended to be used in the class, and as such it's something that is subject to random pedagogic needs and not as something to be used for random Racket code... So my class notes are the main place that "documents" the language.)
来源:https://stackoverflow.com/questions/49465474/return-a-pair-syntax-error