-> denotes a function type. You use it in declare forms, class
method types, local declarations, and inline lisp type signatures.
Syntax
;; in types
⟨type-product⟩ [&key ...] -> ⟨type-product⟩
;; in Lisp forms
(lisp (-> ⟨type-product⟩) ...)
;; ⟨type-product⟩ := ⟨type⟩
;; | ⟨type-product⟩ * ⟨type⟩
Semantics
A -> Bmeans a function fromAtoB.A * B -> Cmeans a fixed-arity two-argument function.Void -> Tis a true nullary function type.T -> Voidis a function type that returns no values.- In
lispforms, the arrow separates the output type list from the embedded Lisp variable list. - Keyword argument lists can precede
->.
Options
- Put
&keybetween positional inputs and->to describe keyword arguments. - Use explicit
forallwhen you want the type variables named in the signature to be in lexical scope inside the body.
Example
(coalton-toplevel
(declare add2 (Integer -> Integer))
(define (add2 x)
(+ x 2)))