Return a pair - syntax error

。_饼干妹妹 提交于 2019-12-24 10:47:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!