【问题标题】:contract for function that only cares about return value?只关心返回值的功能合同?
【发布时间】:2017-06-13 18:19:07
【问题描述】:

假设以下平凡函数:

(define/contract (foo func)
  (-> (-> any/c ... any/c) #t)
  #t)

这是试图(但失败)表达“foo 接受一个处理器函数。我不在乎处理器需要什么参数(这是调用者的工作),但处理器必须返回一个单一的结果。”

foo 的正确合约是什么?我已经阅读了关于功能合同的部分;以上是我的第一个猜测,但失败了:

(foo identity)
; foo: contract violation
;   expected: a procedure that accepts 0 non-keyword arguments and arbitrarily
;     many more
;   given: #<procedure:identity>
;   identity accepts: 1 argument
;   in: the 1st argument of
;       (-> (-> any/c ... any/c) #t)
;   contract from: (function foo)
;   blaming: top-level
;    (assuming the contract is correct)
;   at: readline-input:8.18
; [,bt for context]

我也试过这个,这显然不是合法的语法:

(define/contract (foo func)
  (-> (-> any any/c) #t)
  #t)
; readline-input:10:33: any: use of 'any' outside the range of an arrow
;   contract
;   in: any
; [,bt for context]

【问题讨论】:

标签: racket contract


【解决方案1】:

我想你想要unconstrained-domain-&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2022-06-16
    相关资源
    最近更新 更多