* separates multiple positional input types on the left of -> and multiple return value types on the right of ->.
Syntax
;; Multiple positional inputs and/or multiple return values in a function type
(⟨in-type-1⟩ * ⟨in-type-2⟩ [* ...] -> ⟨out-type-1⟩ * ⟨out-type-2⟩ [* ...])
;; Multiple return values in an inline `lisp` form
(lisp (-> ⟨out-type-1⟩ * ⟨out-type-2⟩ [* ...]) (⟨var-spec⟩*)
⟨lisp-form⟩+)
Semantics
- On the left of
->:A * B -> Cdenotes a single two-argument function called as(f a b).- This is distinct from the curried type
A -> B -> C(a one-argument function returning a one-argument function, called as((f a) b)) and from(Tuple A B -> C)(a one-argument function taking aTupledata structure). - When
&keyis also present,&keyfollows the*-separated positional input types:(A * B &key (:k K) -> C).
- On the right of
->(and in(lisp (-> ...) ...)):In -> A * Bdenotes a function returning two values viavalues, which callers can bind with(let (values a b) = (f x)).- When
->appears to the right of->(as inA -> B -> C), the right-hand side is parsed as a curried function return type rather than a*pack. Wrap a function component of a multi-value return in parentheses:(In -> (A -> B) * C).
- Component restrictions:
- Every component separated by
*must be a single-value type;Voidand nested multi-value packs cannot appear as components of a*list. - A multi-value pack
A * Bcannot be used as a function input argument, a type constructor argument (such asList (A * B)), or a standalonedeclaretype.
- Every component separated by
Examples
(coalton-toplevel
;; Two positional inputs and two return values
(declare divmod (Integer * Integer -> Integer * Integer))
(define (divmod a b)
(values (coalton/math:div a b) (mod a b)))
;; Destructure the multiple return values with `let (values ...) = ...`
(declare euclidean-step (Integer * Integer -> Integer))
(define (euclidean-step a b)
(let (values _q r) = (divmod a b))
r))
Other notes
- In expression contexts,
*is the multiplication method of theNumtype class ((coalton/classes:* x y)). - Surrounding a variable name with
*earmuffs (*name*) designates a dynamic variable indefineanddynamic-bind. - In
kind-ofoutput,*is the printed representation of theTypekind.