返回一对 - 语法错误 [英] Return a pair - syntax error

查看:126
本文介绍了返回一对 - 语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在球拍中使用 pl https:/ /pl.barzilay.org/
可以在这里找到下载: http: //:.barzilay.org/pl.plt

 (:f1: - >(Pairof Symbol String ))
(define(f1)
(cons'wwwwaaa))

错误:

 类型检查器:多态函数`cons'不能应用于参数:
参数1 :
预期:a
鉴于:'wwww
参数2:
预期:(列表a)
鉴于:字符串

结果类型:(a的列表)
预期的结果:(对符号字符串)
in:(cons(quote wwww)aaa)

我做错了什么,我该如何解决它?

code> #lang pl 我在课堂上使用的语言是Typed
球拍的变种。其中一个变化是 cons 具有更受限制的
类型(如您所见),它允许它只构造正确的列表
$ b

(作为旁注,没有正式文档的原因是这个
语言打算在类中使用,并且作为例如
是受随机教育需求的影响,而不是作为随机球拍代码使用的
的东西......所以我的课堂笔记是
的主要场所,用于记录语言。)


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?

解决方案

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.)

这篇关于返回一对 - 语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆