我在 Racket 中使用 pl
:https://pl.barzilay.org/
下载可以在这里找到:http://pl.barzilay.org/pl.plt
( : f1 : -> (Pairof Symbol String))
(define (f1)
(cons 'wwww "aaa"))
错误:
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")
我做错了什么,我该如何解决?
最佳答案
我在类里面使用的#lang pl
语言是 Typed 的变体
Racket 。它的变化之一是 cons
有一个更严格的限制
类型(如您所见),它只允许构建正确的列表。
(作为旁注,没有正式文档的原因是这个 语言是要在类里面使用的,因此它是 这取决于随机的教学需求,而不是作为某种东西 用于随机 Racket 代码......所以我的类笔记是主要的地方 “记录”语言。)
关于functional-programming - 返回一对 - 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49465474/