1
假設以下瑣碎的功能:只關心返回值的函數契約?
(define/contract (foo func)
(-> (-> any/c ... any/c) #t)
#t)
這是試圖(和失敗)表達的想法「富需要一個處理器功能我不在乎(這是調用程序作業)處理器需要什麼論點,但處理器必須返回一個單一的結果。「
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]
原始Q/A :https://groups.google.com/d/msg/racket-users/YLGstyj-o_U/lhKKctSTBwAJ –