Reputation: 13710
I have a function whose single argument can be one of:
eval
within a context)How to express this as a contract for this argument?
My first guess was:
(or/c expr? list?)
Any better ideas or this is right?
Upvotes: 0
Views: 29
Reputation: 2137
Since expr?
does not exist, you should either use procedure?
or something using the arrow constructor (for example (-> number? any/c)
) for the function part of the contract.
Moreover, since this is a contract for a function, you should include both domain and range using ->
.
Example:
#lang racket
(require racket/contract)
(require rackunit)
(define/contract (f x)
(-> (or/c (-> number? number?) list?) (or/c number? list?))
(if (list? x)
x
(x 3)))
(check-equal? (f '()) '())
(check-equal? (f add1) 4)
Upvotes: 1