Introduce pseudovariadic functions.
This commit is contained in:
parent
1f281d3851
commit
8b838c0b22
1 changed files with 31 additions and 1 deletions
|
@ -18,7 +18,37 @@ Boolean functions, etc.).
|
|||
[sandbox-memory-limit 50])
|
||||
(make-evaluator 'typed/racket #:requires '((submod "functions.rkt" typed)))))
|
||||
|
||||
@section{Tabulating functions}
|
||||
@section{Pseudovariadic functions}
|
||||
|
||||
Functions for @seclink["tabulating"]{tabulating functions} take as an argument
|
||||
a function to tabulate or a list of functions to tabulate. Writing the type of
|
||||
such functions in Typed Racket and generalizing on the number of the arguments
|
||||
is hard, and using functions with such types seems even harder.
|
||||
The @seclink["tabulating"]{following section} contains some examples,
|
||||
illustrating among other things the difficulties of typing
|
||||
tabulating functions.
|
||||
|
||||
The type of @racket[apply] does not help in this situation, because Typed
|
||||
Racket treats @racket[apply] in
|
||||
@hyperlink["https://racket.discourse.group/t/replicating-the-type-of-apply/770/3"]{a
|
||||
special way}. This means that a user-defined function with the same type as
|
||||
@racket[apply] and directly calling it will not work in the same way.
|
||||
|
||||
@examples[#:eval functions-evaluator
|
||||
apply
|
||||
(define myapply apply)
|
||||
myapply
|
||||
(apply (λ (x y) (and x y)) '(#t #f))
|
||||
(eval:error (myapply (λ (x y) (and x y)) '(#t #f)))
|
||||
]
|
||||
|
||||
One way to work around this issue is to write functions which disguise as
|
||||
variadic functions of type @racket[(-> a * b)], but which throw an exception
|
||||
when they receive a number of arguments different from a given constant value.
|
||||
Such functions are called @italic{pseudovariadic functions} in
|
||||
this documentation.
|
||||
|
||||
@section[#:tag "tabulating"]{Tabulating functions}
|
||||
|
||||
@defproc[(tabulate [func (-> a ... b)]
|
||||
[doms (List (Listof a) ... a)])
|
||||
|
|
Loading…
Reference in a new issue