declare gives an explicit type to a value, function, or local binding.
Syntax
(declare ⟨name⟩ ⟨type⟩)
Semantics
- Top-level
declareis commonly paired withdefine. - Local
declarealso works inside binding lists oflet,let*,for, andfor*. - Coalton infers types, but
declareis the main way to make intent explicit. - Using
forallmakes the type variables scoped to the variable’s definition.
Example
(declare x Integer)
;; Scoped type variables
(declare keep-first (forall (:a :b) :a -> :b -> :a))
;; Inside of a binding list
(let ((declare x Integer)
(x 5))
(1+ x))