只关心回报价值的函数合约?

时间:2017-06-13 18:19:08

标签: racket contract

假设以下简单的功能:

(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]

1 个答案:

答案 0 :(得分:1)

我想你想要unconstrained-domain->

相关问题