只关心 return 值的功能合同?
contract for function that only cares about return value?
假设以下简单函数:
(define/contract (foo func)
(-> (-> any/c ... any/c) #t)
#t)
这是在尝试(但未能)表达想法 "foo takes a processor function. I don't care what arguments the processor requires (that's the caller's job) but the processor must return a singular result."
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]
假设以下简单函数:
(define/contract (foo func)
(-> (-> any/c ... any/c) #t)
#t)
这是在尝试(但未能)表达想法 "foo takes a processor function. I don't care what arguments the processor requires (that's the caller's job) but the processor must return a singular result."
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]