Public Variables and Functions
ASeq
type alias
Usage: (ASeq t)
A sequential seq returned from clojure.core/seq
Source
AVec
type alias
Usage: (AVec t)
A persistent vector returned from clojure.core/vector (and others)
Source
Agent1
type alias
Usage: (Agent1 t)
An agent that can read and write type x.
Source
Agent2
type alias
Usage: (Agent2 t t)
An agent that can write type w and read type r.
Source
All
type alias
Usage: (All binder type)
A polymorphic binder
Source
Any
type alias
Usage: Any
Any is the top type that contains all types.
Source
AnyInteger
type alias
Usage: AnyInteger
A type that returns true for clojure.core/integer?
Source
AnyValue
type alias
Usage: AnyValue
AnyValue contains all Value singleton types
Source
Assoc
type alias
Usage: (Assoc type type-pairs*)
A type representing an assoc operation
Source
Atom1
type alias
Usage: (Atom1 t)
An atom that can read and write type x.
Source
Atom2
type alias
Usage: (Atom2 t)
An atom that can write type w and read type r.
Source
BlockingDeref
type alias
Usage: (BlockingDeref t)
A Clojure blocking derefable (see clojure.core/deref).
Source
Bool
type alias
Usage: Bool
A boolean
Source
Coll
type alias
Usage: (Coll t)
A persistent collection with member type x.
Source
CountRange
type alias
Usage: (CountRange Integer)
(CountRange Integer Integer)
A type representing a range of counts for a collection
Source
Delay
type alias
Usage: (Delay t)
A Clojure delay (see clojure.core/{delay,force}).
Source
Deref
type alias
Usage: (Deref t)
A Clojure derefable (see clojure.core/deref).
Source
Difference
type alias
Usage: (Difference type type type*)
Difference represents a difference of types.
(Difference t s) is the same as type t with type s removed.
eg. (Difference (U Int Long) Int) => Long
(Difference (U Num nil) nil) => Num
Source
Dissoc
type alias
Usage: (Dissoc type type*)
A type representing a dissoc operation
Source
EmptyCount
type alias
Usage: EmptyCount
The type of all things with count 0. Use as part of an intersection.
eg. See EmptySeqable.
Source
EmptySeqable
type alias
Usage: (EmptySeqable t)
A type that can be used to create a sequence of member type x
with count 0.
Source
ExInfo
type alias
Usage: ExInfo
A Clojure custom exception type.
Source
ExactCount
type alias
Usage: (ExactCount Integer)
A type representing a precise count for a collection
Source
Fn
type alias
Usage: Fn
A type that returns true for clojure.core/fn?
Source
Future
type alias
Usage: (Future t)
A Clojure future (see clojure.core/{future-call,future}).
Source
Get
type alias
Usage: (Get type type)
(Get type type type)
A type representing a get operation
Source
HMap
type alias
Usage: (HMap :mandatory {Constant Type*} :optional {Constant Type*} :absent-keys #{Constant*} :complete? Boolean)
(quote {Constant Type*})
HMap is a type for heterogeneous maps.
Source
HSeq
type alias
Usage: (HSeq [fixed*] :filter-sets [FS*] :objects [obj*])
(HSeq [fixed* rest *] :filter-sets [FS*] :objects [obj*])
(HSeq [fixed* drest ... bound] :filter-sets [FS*] :objects [obj*])
HSeq is a type for heterogeneous seqs
Source
HSequential
type alias
Usage: (HSequential [fixed*] :filter-sets [FS*] :objects [obj*])
(HSequential [fixed* rest *] :filter-sets [FS*] :objects [obj*])
(HSequential [fixed* drest ... bound] :filter-sets [FS*] :objects [obj*])
HSequential is a type for heterogeneous sequential collections
Source
HSet
type alias
Usage: (HSet #{fixed*} :complete? Boolean)
HSet is a type for heterogeneous sets.
Takes a set of simple values. By default
:complete? is true.
eg. (HSet #{:a :b :c} :complete? true)
Source
HVec
type alias
Usage: (HVec [fixed*] :filter-sets [FS*] :objects [obj*])
(HVec [fixed* type *] :filter-sets [FS*] :objects [obj*])
(HVec [fixed* type ... bound] :filter-sets [FS*] :objects [obj*])
(quote [fixed*])
(quote [fixed* type *])
(quote [fixed* type ... bound])
HVec is a type for heterogeneous vectors.
It extends clojure.core.typed/Vec and is a subtype
of clojure.core.typed/HSequential.
Source
Hierarchy
type alias
Usage: Hierarchy
A hierarchy for use with derive, isa? etc.
Source
I
type alias
Usage: (I type*)
I represents an intersection of types
Source
IFn
type alias
Usage: (IFn ArityVec+)
[fixed* -> ret :filters {:then fl, :else fl} :object {:id Foo, :path Bar}]
[fixed* rest * -> ret :filters {:then fl, :else fl} :object {:id Foo, :path Bar}]
[fixed* drest ... bound -> ret :filters {:then fl, :else fl} :object {:id Foo, :path Bar}]
An ordered intersection type of function arities.
Source
Id
type alias
Usage: Id
The identity function at the type level.
Source
Int
type alias
Usage: Int
A type that returns true for clojure.core/integer?
Source
Keyword
type alias
Usage: Keyword
A keyword
Source
Kw
type alias
Usage: Kw
A keyword
Source
List
type alias
Usage: (List t)
A Clojure persistent list.
Source
Map
type alias
Usage: (Map t t)
A persistent map with keys k and vals v.
Source
Multi
type alias
Usage: Multi
A Clojure multimethod.
Source
Namespace
type alias
Usage: Namespace
A namespace
Source
Nilable
type alias
Usage: (Nilable t)
A union of x and nil.
Source
NilableNonEmptyASeq
type alias
Usage: (NilableNonEmptyASeq t)
The result of clojure.core/seq.
Source
NilableNonEmptySeq
type alias
Usage: (NilableNonEmptySeq t)
A persistent sequence of member type x with count greater than 0, or nil.
Source
NonEmptyASeq
type alias
Usage: (NonEmptyASeq t)
A sequential non-empty seq retured from clojure.core/seq
Source
NonEmptyAVec
type alias
Usage: (NonEmptyAVec t)
A persistent vector returned from clojure.core/vector (and others) and count greater than 0.
Source
NonEmptyColl
type alias
Usage: (NonEmptyColl t)
A persistent collection with member type x and count greater than 0.
Source
NonEmptyCount
type alias
Usage: NonEmptyCount
The type of all things with count greater than 0. Use as part of an intersection.
eg. See NonEmptySeq
Source
NonEmptyLazySeq
type alias
Usage: (NonEmptyLazySeq t)
A non-empty lazy sequence of type t
Source
NonEmptySeq
type alias
Usage: (NonEmptySeq t)
A persistent sequence of member type x with count greater than 0.
Source
NonEmptySeqable
type alias
Usage: (NonEmptySeqable t)
A type that can be used to create a sequence of member type x
with count greater than 0.
Source
NonEmptyVec
type alias
Usage: (NonEmptyVec t)
A persistent vector with member type x and count greater than 0.
Source
Nothing
type alias
Usage: Nothing
Nothing is the bottom type that inhabits no types
except itself.
Source
Num
type alias
Usage: Num
A type that returns true for clojure.core/number?
Source
Option
type alias
Usage: (Option t)
A union of x and nil.
Source
Pred
type alias
Usage: (Pred type)
A predicate for the given type.
eg. Type for integer?: (Pred Int)
Source
Promise
type alias
Usage: (Promise t)
A Clojure promise (see clojure.core/{promise,deliver}).
Source
Proxy
type alias
Usage: Proxy
A Clojure proxy.
Source
Rec
type alias
Usage: (Rec binder type)
A recursive type
Source
Ref1
type alias
Usage: (Ref1 t)
A ref that can read and write type x.
Source
Ref2
type alias
Usage: (Ref2 w r)
A ref that can write type w and read type r.
Source
Reversible
type alias
Usage: (Reversible t)
A Clojure reversible collection.
Source
Seq
type alias
Usage: (Seq t)
A persistent sequence of member type x.
Source
Seqable
type alias
Usage: (Seqable t)
A type that can be used to create a sequence of member type x.
Source
Sequential
type alias
Usage: Sequential
A sequential collection.
Source
SequentialSeq
type alias
Usage: (SequentialSeq t)
A Clojure sequential sequence. Seq's aren't always Sequential.
Source
SequentialSeqable
type alias
Usage: (SequentialSeqable t)
A sequential, seqable collection. Seq's aren't always Sequential.
Source
Set
type alias
Usage: (Set t)
A persistent set with member type x
Source
SortedSet
type alias
Usage: (SortedSet t)
A sorted persistent set with member type x
Source
Stack
type alias
Usage: (Stack t)
A Clojure stack.
Source
Str
type alias
Usage: Str
A string
Source
Sym
type alias
Usage: Sym
A symbol
Source
Symbol
type alias
Usage: Symbol
A symbol
Source
TFn
type alias
Usage: (TFn binder type)
A type function
Source
U
type alias
Usage: (U type*)
U represents a union of types
Source
Val
type alias
Usage: (Val Constant)
(quote Constant)
A singleton type for a constant value.
Source
Value
type alias
Usage: (Value Constant)
(quote Constant)
A singleton type for a constant value.
Source
Var1
type alias
Usage: (Var1 t)
An var that can read and write type x.
Source
Var2
type alias
Usage: (Var2 w r)
An var that can write type w and read type r.
Source
Vec
type alias
Usage: (Vec t)
A persistent vector with member type x.
Source
ann
macro
Usage: (ann varsym typesyn)
Annotate varsym with type. If unqualified, qualify in the current namespace.
If varsym has metadata {:no-check true}, ignore definitions of varsym
while type checking.
If annotating vars in namespaces other than the current one, a fully
qualified symbol must be provided. Note that namespace aliases are not
recognised: the *full* namespace must be given in the first part of the symbol.
eg. ; annotate the var foo in this namespace
(ann foo [Number -> Number])
; annotate a var in another namespace
(ann another.ns/bar [-> nil])
; don't check this var
(ann ^:no-check foobar [Integer -> String])
Source
ann-datatype
macro
Usage: (ann-datatype dname [field :- type*] opts*)
(ann-datatype binder dname [field :- type*] opts*)
Annotate datatype Class name dname with expected fields.
If unqualified, qualify in the current namespace.
Takes an optional type variable binder before the name.
Fields must be specified in the same order as presented
in deftype, with exactly the same field names.
Also annotates datatype factories and constructors.
Binder is a vector of specs. Each spec is a vector
with the variable name as the first entry, followed by
keyword arguments:
- :variance (mandatory)
The declared variance of the type variable. Possible
values are :covariant, :contravariant and :invariant.
- :< (optional)
The upper type bound of the type variable. Defaults to
Any, or the most general type of the same rank as the
lower bound.
- :> (optional)
The lower type bound of the type variable. Defaults to
Nothing, or the least general type of the same rank as the
upper bound.
eg. ; a datatype in the current namespace
(ann-datatype MyDatatype [a :- Number,
b :- Long])
; a datatype in another namespace
(ann-datatype another.ns.TheirDatatype
[str :- String,
vec :- (Vec Number)])
; a datatype, polymorphic in a
(ann-datatype [[a :variance :covariant]]
MyPolyDatatype
[str :- String,
vec :- (Vec Number)
ply :- (Set a)])
Source
macro
Usage: (ann-form form ty)
Annotate a form with an expected type.
ann-interface
macro
Usage: (ann-interface vbnd varsym & methods)
(ann-interface varsym & methods)
Annotate a possibly polymorphic interface (created with definterface) with method types.
Note: Unlike ann-protocol, omit the target ('this') argument in the method signatures.
eg. (ann-interface IFoo
bar
(Fn [-> Any]
[Number Symbol -> Any])
baz
[Number -> Number])
(definterface IFoo
(bar [] [n s])
(baz [n]))
; polymorphic protocol
; x is scoped in the methods
(ann-protocol [[x :variance :covariant]]
IFooPoly
bar
(Fn [-> Any]
[Number Symbol -> Any])
baz
[Number -> Number])
(definterface IFooPoly
(bar [] [n s])
(baz [n]))
Source
ann-many
macro
Usage: (ann-many t & vs)
Annotate several vars with type t.
eg. (ann-many FakeSearch
web1 web2 image1 image2 video1 video2)
Source
ann-precord
macro
Usage: (ann-precord dname vbnd fields & {ancests :unchecked-ancestors, rplc :replace, :as opt})
Annotate record Class name dname with a polymorphic binder and expected fields.
If unqualified, qualify in the current namespace.
Source
ann-protocol
macro
Usage: (ann-protocol vbnd varsym & methods)
(ann-protocol varsym & methods)
Annotate a possibly polymorphic protocol var with method types.
eg. (ann-protocol IFoo
bar
(Fn [IFoo -> Any]
[IFoo Number Symbol -> Any])
baz
[IFoo Number -> Number])
(defprotocol> IFoo
(bar [this] [this n s])
(baz [this n]))
; polymorphic protocol
; x is scoped in the methods
(ann-protocol [[x :variance :covariant]]
IFooPoly
bar
(Fn [(IFooPoly x) -> Any]
[(IFooPoly x) Number Symbol -> Any])
baz
[(IFooPoly x) Number -> Number])
(defprotocol> IFooPoly
(bar [this] [this n s])
(baz [this n]))
Source
ann-record
macro
Usage: (ann-record dname [field :- type*] opts*)
(ann-record binder dname [field :- type*] opts*)
Annotate record Class name dname with expected fields.
If unqualified, qualify in the current namespace.
Takes an optional type variable binder before the name.
Fields must be specified in the same order as presented
in defrecord, with exactly the same field names.
Also annotates record factories and constructors.
Binder is a vector of specs. Each spec is a vector
with the variable name as the first entry, followed by
keyword arguments:
- :variance (mandatory)
The declared variance of the type variable. Possible
values are :covariant, :contravariant and :invariant.
- :< (optional)
The upper type bound of the type variable. Defaults to
Any, or the most general type of the same rank as the
lower bound.
- :> (optional)
The lower type bound of the type variable. Defaults to
Nothing, or the least general type of the same rank as the
upper bound.
eg. ; a record in the current namespace
(ann-record MyRecord [a :- Number,
b :- Long])
; a record in another namespace
(ann-record another.ns.TheirRecord
[str :- String,
vec :- (Vec Number)])
; a record, polymorphic in a
(ann-record [[a :variance :covariant]]
MyPolyRecord
[str :- String,
vec :- (Vec Number)
ply :- (Set a)])
Source
atom
macro
Usage: (atom & args)
Like atom, but with optional type annotations.
Same as (atom (ann-form init t) args*)
eg. (atom 1) : (Atom1 (Value 1))
(atom :- Num, 1) : (Atom1 Num)
atom>
macro
Usage: (atom> t init & args)
DEPRECATED: use clojure.core.typed/atom
Like atom, but creates an Atom1 of type t.
Same as (atom (ann-form init t) args*)
eg. (atom> Number 1)
(atom> (Vec Any) [])
Deprecated since Gradual Typing version 0.2.58
Source
cast
macro
Usage: (cast t x)
(cast t x opt)
Cast a value to a type. Returns a new value that conforms
to the given type, otherwise throws an error with blame.
eg. (cast Int 1)
;=> 1
(cast Int nil)
; Fail, <blame positive ...>
((cast [Int -> Int] identity)
1)
;=> 1
((cast [Int -> Int] identity)
nil)
; Fail, <blame negative ...>
(cast [Int -> Int] nil)
; Fail, <blame positive ...>
(defalias Options
(HMap :optional {:positive (U Sym Str),
:negative (U Sym Str)
:file (U Str nil)
:line (U Int nil)
:column (U Int nil)}))
(IFn [Contract Any -> Any]
[Contract Any Options -> Any]
Options:
- :positive positive blame, (U Sym Str)
- :negative negative blame, (U Sym Str)
- :file file name where contract is checked, (U Str nil)
- :line line number where contract is checked, (U Int nil)
- :column column number where contract is checked, (U Int nil)
Source
cf
macro
Usage: (cf form)
(cf form expected)
Takes a form and an optional expected type and
returns a human-readable inferred type for that form.
Throws an exception if type checking fails.
Do not use cf inside a typed namespace. cf is intended to be
used at the REPL or within a unit test. Note that testing for
truthiness is not sufficient to unit test a call to cf, as nil
and false are valid type syntax.
cf preserves annotations from previous calls to check-ns or cf,
and keeps any new ones collected during a cf. This is useful for
debugging and experimentation. cf may be less strict than check-ns
with type checker warnings.
eg. (cf 1)
;=> Long
(cf #(inc %) [Number -> Number])
;=> [Number -> Number]
Source
function
Usage: (check-form* form)
(check-form* form expected)
(check-form* form expected type-provided?)
Takes a (quoted) form and optional expected type syntax and
type checks the form. If expected is provided, type-provided?
must be true.
Source
function
Usage: (check-form-info form & opt)
Type checks a (quoted) form and returns a map of results from type checking the
form.
Options
- :expected Type syntax representing the expected type for this form
type-provided? option must be true to utilise the type.
- :type-provided? If true, use the expected type to check the form.
- :profile Use Timbre to profile the type checker. Timbre must be
added as a dependency. Must use the "slim" JAR.
- :file-mapping If true, return map provides entry :file-mapping, a hash-map
of (Map '{:line Int :column Int :file Str} Str).
- :checked-ast Returns the entire AST for the given form as the :checked-ast entry,
annotated with the static types inferred after checking.
If a fatal error occurs, mapped to nil.
- :no-eval If true, don't evaluate :out-form. Removes :result return value.
It is highly recommended to evaluate :out-form manually.
Default return map
- :ret TCResult inferred for the current form
- :out-form The macroexpanded result of type-checking, if successful.
- :result The evaluated result of :out-form, unless :no-eval is provided.
- :ex If an exception was thrown during evaluation, this key will be present
with the exception as the value.
DEPRECATED
- :delayed-errors A sequence of delayed errors (ex-info instances)
Source
check-ns
function
Usage: (check-ns)
(check-ns ns-or-syms & opt)
Type check a namespace/s (a symbol or Namespace, or collection).
If not provided default to current namespace.
Returns a true value if type checking is successful, otherwise
throws an Exception.
Do not use check-ns within a checked namespace.
It is intended to be used at the REPL or within a unit test.
Suggested idiom for clojure.test: (is (check-ns 'your.ns))
check-ns resets annotations collected from
previous check-ns calls or cf. A successful check-ns call will
preserve any type annotations collect during that checking run.
Keyword arguments:
- :collect-only if true, collect type annotations but don't type check code.
Useful for debugging purposes.
- :trace if true, print some basic tracing of the type checker
- :profile Use Timbre to profile the type checker. Timbre must be
added as a dependency. Must use the "slim" JAR.
If providing keyword arguments, the namespace to check must be provided
as the first argument.
Bind clojure.core.typed.util-vars/*verbose-types* to true to print fully qualified types.
Bind clojure.core.typed.util-vars/*verbose-forms* to print full forms in error messages.
eg. (check-ns 'myns.typed)
;=> :ok
; implicitly check current namespace
(check-ns)
;=> :ok
; collect but don't check the current namespace
(check-ns *ns* :collect-only true)
Source
check-ns-info
function
Usage: (check-ns-info)
(check-ns-info ns-or-syms & opt)
Same as check-ns, but returns a map of results from type checking the
namespace.
Options
- :collect-only Don't type check the given namespace/s, but collect the
top level type annotations like ann, ann-record.
- :type-provided? If true, use the expected type to check the form
- :profile Use Timbre to profile the type checker. Timbre must be
added as a dependency. Must use the "slim" JAR.
- :file-mapping If true, return map provides entry :file-mapping, a hash-map
of (Map '{:line Int :column Int :file Str} Str).
Default return map
- :delayed-errors A sequence of delayed errors (ex-info instances)
Source
declare-alias-kind
macro
Usage: (declare-alias-kind sym ty)
Declare a kind for an alias, similar to declare but on the kind level.
Source
declare-datatypes
macro
Usage: (declare-datatypes & syms)
Declare datatypes, similar to declare but on the type level.
Source
declare-names
macro
Usage: (declare-names & syms)
Declare names, similar to declare but on the type level.
Source
declare-protocols
macro
Usage: (declare-protocols & syms)
Declare protocols, similar to declare but on the type level.
Source
def
macro
Usage: (def name docstring? :- type? expr)
Like clojure.core/def with optional type annotations
NB: in Clojure it is impossible to refer a var called `def` as it is a
special form. Use an alias prefix (eg. `t/def`).
If an annotation is provided, a corresponding `ann` form
is generated, otherwise it expands identically to clojure.core/def
eg. ;same as clojure.core/def
(def vname 1)
;with Number `ann`
(def vname :- Number 1)
;doc
(def vname
"Docstring"
:- Long
1)
def-alias
macro
Usage: (def-alias sym doc-str t)
(def-alias sym t)
DEPRECATED: use defalias
Define a type alias. Takes an optional doc-string as a second
argument.
Updates the corresponding var with documentation.
eg. (def-alias MyAlias
"Here is my alias"
(U nil String))
Deprecated since Gradual Typing version 0.2.45
Source
def>
macro
Usage: (def> name docstring? :- type expr)
DEPRECATED: use clojure.core.typed/def
Like def, but with annotations.
eg. (def> vname :- Long 1)
;doc
(def> vname
"Docstring"
:- Long
1)
Deprecated since Gradual Typing version 0.2.45
Source
defalias
macro
Usage: (defalias sym doc-str t)
(defalias sym t)
Define a recursive type alias. Takes an optional doc-string as a second
argument.
Updates the corresponding var with documentation.
eg. (defalias MyAlias
"Here is my alias"
(U nil String))
;; recursive alias
(defalias Expr
(U '{:op ':if :test Expr :then Expr :else Expr}
'{:op ':const :val Any}))
Source
defn
macro
Usage: (defn kw-args? name docstring? attr-map? [param :- type *] :- type exprs*)
(defn kw-args? name docstring? attr-map? ([param :- type *] :- type exprs*) +)
Like defn, but expands to clojure.core.typed/fn. If a polymorphic binder is
supplied before the var name, expands to clojure.core.typed/pfn.
eg. (defn fname [a :- Number, b :- (U Symbol nil)] :- Integer ...)
;annotate return
(defn fname [a :- String] :- String ...)
;multi-arity
(defn fname
([a :- String] :- String ...)
([a :- String, b :- Number] :- Long ...))
;polymorphic function
(defn :forall [x y]
fname
([a :- x] :- (Coll y) ...)
([a :- Str, b :- y] :- y ...))
defn>
macro
Usage: (defn> name docstring? :- type [param :- type *] exprs*)
(defn> name docstring? (:- type [param :- type *] exprs*) +)
DEPRECATED: Use defn
Like defn, but with annotations. Annotations are mandatory for
parameters and for return type.
eg. (defn> fname :- Integer [a :- Number, b :- (U Symbol nil)] ...)
;annotate return
(defn> fname :- String [a :- String] ...)
;multi-arity
(defn> fname
(:- String [a :- String] ...)
(:- Long [a :- String, b :- Number] ...))
Deprecated since Gradual Typing version 0.2.57
Source
defprotocol
macro
Usage: (defprotocol & body)
Like defprotocol, but with optional type annotations.
Omitted annotations default to Any. The first argument
of a protocol cannot be annotated.
Add a binder before the protocol name to define a polymorphic
protocol. A binder before the method name defines a polymorphic
method, however a method binder must not shadow type variables
introduced by a protocol binder.
Return types for each method arity can be annotated.
Unlike clojure.core/defprotocol, successive methods can
have the same arity. Semantically, providing multiple successive
methods of the same arity is the same as just providing the left-most
method. However the types for these methods will be accumulated into
a Fn type.
eg. ;annotate single method
(defprotocol MyProtocol
(a [this a :- Integer] :- Number))
;polymorphic protocol
(defprotocol [[x :variance :covariant]]
MyProtocol
(a [this a :- Integer] :- Number))
;multiple types for the same method
(defprotocol [[x :variance :covariant]]
MyProtocol
(a [this a :- Integer] :- Integer
[this a :- Long] :- Long
[this a :- Number] :- Number))
;polymorphic method+protocol
(defprotocol [[x :variance :covariant]]
MyProtocol
([y] a [this a :- x, b :- y] :- y))
defprotocol>
macro
Usage: (defprotocol> & body)
DEPRECATED: use clojure.core.typed/defprotocol
Like defprotocol, but required for type checking
its macroexpansion.
eg. (defprotocol> MyProtocol
(a [this]))
Deprecated since Gradual Typing version 0.2.45
Source
doseq
macro
Usage: (doseq seq-exprs & body)
Like clojure.core/doseq with optional annotations.
:let option uses clojure.core.typed/let
eg.
(doseq [a :- (U nil AnyInteger) [1 nil 2 3]
:when a]
(inc a))
Source
doseq>
macro
Usage: (doseq> seq-exprs & body)
DEPRECATED: use clojure.core.typed/doseq
Like doseq but requires annotation for each loop variable:
[a [1 2]] becomes [a :- Long [1 2]]
eg.
(doseq> [a :- (U nil AnyInteger) [1 nil 2 3]
:when a]
(inc a))
Deprecated since Gradual Typing version 0.2.45
Source
dotimes
macro
Usage: (dotimes bindings & body)
Like clojure.core/dotimes, but with optional annotations.
If annotation for binding is omitted, defaults to Int.
eg. (dotimes [_ 100]
(println "like normal"))
(dotimes [x :- Num, 100.123]
(println "like normal" x))
Source
dotimes>
macro
Usage: (dotimes> bindings & body)
DEPRECATED: Use clojure.core.typed/dotimes
Like dotimes.
eg. (dotimes> [_ 100]
(println "like normal"))
Deprecated since Gradual Typing version 0.2.45
Source
envs
function
Usage: (envs)
Returns a map of type environments, according to the current state of the
type checker.
Output map:
- :vars map from var symbols to their verbosely printed types
- :aliases map from alias var symbols (made with defalias) to their verbosely printed types
- :special-types a set of Vars that are special to the type checker (like Any, U, I)
Source
fn
macro
Usage: (fn name? [param :- type* & param :- type * ?] :- type? exprs*)
(fn name? ([param :- type* & param :- type * ?] :- type? exprs*) +)
Like clojure.core/fn, but with optional annotations.
eg. ;these forms are equivalent
(fn [a] b)
(fn [a :- Any] b)
(fn [a :- Any] :- Any b)
(fn [a] :- Any b)
;annotate return
(fn [a :- String] :- String body)
;named fn
(fn fname [a :- String] :- String body)
;rest parameter
(fn [a :- String & b :- Number *] body)
;dotted rest parameter
(fn [a :- String & b :- Number ... x] body)
;multi-arity
(fn fname
([a :- String] :- String ...)
([a :- String, b :- Number] :- String ...))
; polymorphic binder
(fn :forall [x y z]
fname
([a :- String] :- String ...)
([a :- String, b :- Number] :- String ...))
fn>
macro
Usage: (fn> name? :- type? [param :- type* & param :- type * ?] exprs*)
(fn> name? (:- type? [param :- type* & param :- type * ?] exprs*) +)
DEPRECATED: use clojure.core.typed/fn
Like fn, but with annotations. Annotations are mandatory
for parameters, with optional annotations for return type.
If fn is named, return type annotation is mandatory.
Suggested idiom: use commas between parameter annotation triples.
eg. (fn> [a :- Number, b :- (U Symbol nil)] ...)
;annotate return
(fn> :- String [a :- String] ...)
;named fn
(fn> fname :- String [a :- String] ...)
;multi-arity
(fn> fname
(:- String [a :- String] ...)
(:- Long [a :- String, b :- Number] ...))
Deprecated since Gradual Typing version 0.2.45
Source
for
macro
Usage: (for seq-exprs & maybe-ann-body-expr)
Like clojure.core/for with optional type annotations.
All types default to Any.
The :let option uses clojure.core.typed/let.
eg. (for [a :- (U nil Int) [1 nil 2 3]
:when a]
:- Number
(inc a))
Source
for>
macro
Usage: (for> tk ret-ann seq-exprs body-expr)
DEPRECATED: use clojure.core.typed/for
Like for but requires annotation for each loop variable: [a [1 2]] becomes [a :- Long [1 2]]
Also requires annotation for return type.
eg. (for> :- Number
[a :- (U nil AnyInteger) [1 nil 2 3]
:when a]
(inc a))
Deprecated since Gradual Typing version 0.2.45
Source
inst
macro
Usage: (inst inst-of & types)
Instantiate a polymorphic type with a number of types.
eg. (inst foo-fn t1 t2 t3 ...)
Source
inst-ctor
macro
Usage: (inst-ctor inst-of & types)
Instantiate a call to a constructor with a number of types.
First argument must be an immediate call to a constructor.
Returns exactly the instantiatee (the first argument).
eg. (inst-ctor (PolyCtor. a b c)
t1 t2 ...)
Source
install
function
Usage: (install)
(install features)
Install the :core.typed :lang. Takes an optional set of features
to install, defaults to `:all`, which is equivalent to the set of
all features.
Features:
- :load Installs typed `load` over `clojure.core/load`, which type checks files
on the presence of a {:lang :core.typed} metadata entry in the `ns` form.
The metadata must be inserted in the actual `ns` form saved to disk,
as it is read directly from the file instead of the current Namespace
metadata.
- :eval Installs typed `eval` over `clojure.core/eval`.
If `(= :core.typed (:lang (meta *ns*)))` is true, the form will be implicitly
type checked. The syntax save to disk is ignored however.
eg. (install) ; installs `load` and `eval`
eg. (install :all) ; installs `load` and `eval`
eg. (install #{:eval}) ; installs `eval`
eg. (install #{:load}) ; installs `load`
Source
into-array>
macro
Usage: (into-array> cljt coll)
(into-array> javat cljt coll)
(into-array> into-array-syn javat cljt coll)
Make a Java array with Java class javat and Typed Clojure type
cljt. Resulting array will be of type javat, but elements of coll must be under
cljt. cljt should be a subtype of javat (the same or more specific).
*Temporary hack*
into-array-syn is exactly the syntax to put as the first argument to into-array.
Calling resolve on this syntax should give the correct class.
Source
let
macro
Usage: (let [binding :- type? init*] exprs*)
Like clojure.core/let but supports optional type annotations.
eg. (let [a :- Type, b
a2 1.2]
body)
letfn>
macro
Usage: (letfn> [fn-spec-or-annotation*] expr*)
Like letfn, but each function spec must be annotated.
eg. (letfn> [a :- [Number -> Number]
(a [b] 2)
c :- [Symbol -> nil]
(c [s] nil)]
...)
Source
load-if-needed
function
Usage: (load-if-needed)
Load and initialize all of core.typed if not already
Source
loop
macro
Usage: (loop [binding :- type? init*] exprs*)
Like clojure.core/loop, and supports optional type annotations.
Arguments default to a generalised type based on the initial value.
eg. (loop [a :- Number 1
b :- (U nil Number) nil]
...)
loop>
macro
Usage: (loop> [binding :- type init*] exprs*)
DEPRECATED: use clojure.core.typed/loop
Like loop, except loop variables require annotation.
Suggested idiom: use a comma between the type and the initial
expression.
eg. (loop> [a :- Number, 1
b :- (U nil Number), nil]
...)
Deprecated since Gradual Typing version 0.2.45
Source
method-type
function
Usage: (method-type mname)
Given a method symbol, print the core.typed types assigned to it.
Intended for use at the REPL.
Source
nilable-param
macro
Usage: (nilable-param msym mmap)
Override which parameters in qualified method msym may accept
nilable values. If the parameter is a parameterised type or
an Array, this also declares the parameterised types and the Array type as nilable.
mmap is a map mapping arity parameter number to a set of parameter
positions (integers). If the map contains the key :all then this overrides
other entries. The key can also be :all, which declares all parameters nilable.
Source
non-nil-return
macro
Usage: (non-nil-return msym arities)
Override the return type of fully qualified method msym to be non-nil.
Takes a set of relevant arities,
represented by the number of parameters it takes (rest parameter counts as one),
or :all which overrides all arities.
eg. ; must use full class name
(non-nil-return java.lang.Class/getDeclaredMethod :all)
Source
override-constructor
macro
Usage: (override-constructor ctorsym typesyn)
Override all constructors for Class ctorsym with type.
Source
override-method
macro
Usage: (override-method methodsym typesyn)
Override type for qualified method methodsym.
methodsym identifies the method to override and should be a
namespace-qualified symbol in the form <class>/<method-name>.
The class name needs to be fully qualified.
typesyn uses the same annotation syntax as functions.
Use non-nil-return instead of override-method if you want to
declare that a method can never return nil.
Example:
(override-method java.util.Properties/stringPropertyNames
[-> (java.util.Set String)])
This overrides the return type of method stringPropertyNames
of class java.util.Properties to be (java.util.Set String).
Source
pfn>
macro
Usage: (pfn> & forms)
Define a polymorphic typed anonymous function.
(pfn> name? [binder+] :- type? [[param :- type]* & [param :- type *]?] exprs*)
(pfn> name? [binder+] (:- type? [[param :- type]* & [param :- type *]?] exprs*)+)
Source
pred
macro
Usage: (pred t)
Generate a flat (runtime) predicate for type that returns true if the
argument is a subtype of the type, otherwise false.
The current type variable and dotted type variable scope is cleared before parsing.
eg. ((pred Number) 1)
;=> true
Source
print-env
function
Usage: (print-env debug-str)
During type checking, print the type environment to *out*,
preceeded by literal string debug-str.
Source
print-filterset
function
Usage: (print-filterset debug-string frm)
During type checking, print the filter set attached to form,
preceeded by literal string debug-string.
Returns nil.
eg. (let [s (seq (get-a-seqable))]
(print-filterset "Here now" s))
Source
ref
macro
Usage: (ref & args)
Like ref, but with optional type annotations.
Same as (ref (ann-form init t) args*)
eg. (ref 1) : (Ref1 (Value 1))
(ref :- Num, 1) : (Ref1 Num)
ref>
macro
Usage: (ref> t init & args)
DEPRECATED: use clojure.core.typed/ref
Like ref, but creates a Ref1 of type t.
Same as (ref (ann-form init t) args*)
eg. (ref> Number 1)
(ref> (Vec Any) [])
Deprecated since Gradual Typing version 0.2.58
Source
reset-caches
function
Usage: (reset-caches)
Reset internal type caches.
Source
runtime-infer
function
Usage: (runtime-infer)
(runtime-infer ns)
Infer and insert annotations for a given namespace.
To instrument your namespace, use the :runtime-infer
feature in your namespace metadata. Note: core.typed
must be installed via `clojure.core.typed/install`.
eg. (ns my-ns
{:lang :core.typed
:core.typed {:features #{:runtime-infer}}}
(:require [clojure.core.typed :as t]))
After your namespace is instrumented, run your tests
and/or exercise the functions in your namespace.
Then call `runtime-infer` to populate the namespace's
corresponding file with these generated annotations.
eg. (runtime-infer) ; infer for *ns*
(runtime-infer 'my-ns) ; infer for my-ns
Source
statistics
function
Usage: (statistics nsyms)
Takes a collection of namespace symbols and returns a map mapping the namespace
symbols to a map of data
Source
tc-ignore
macro
Usage: (tc-ignore & body)
Ignore forms in body during type checking
typed-deps
macro
Usage: (typed-deps & args)
Declare namespaces which should be checked before the current namespace.
Accepts any number of symbols. Only has effect via check-ns.
eg. (typed-deps clojure.core.typed.holes
myns.types)
Source
untyped-var
macro
Usage: (untyped-var varsym typesyn)
Check a given var has the specified type at runtime.
Source
var-coverage
function
Usage: (var-coverage)
(var-coverage nsyms-or-nsym)
Summarises annotated var coverage statistics to *out*
for namespaces nsyms, a collection of symbols or a symbol/namespace.
Defaults to the current namespace if no argument provided.
Source
var>
macro
Usage: (var> sym)
Like var, but resolves at runtime like ns-resolve and is understood by
the type checker. sym must be fully qualified (without aliases).
eg. (var> clojure.core/+)
Source
warn-on-unannotated-vars
macro
Usage: (warn-on-unannotated-vars)
Allow unannotated vars in the current namespace.
Emits a warning instead of a type error when checking
a def without a corresponding expected type.
Disables automatic inference of `def` expressions.
eg. (warn-on-unannotated-vars)
Source
when-let-fail
macro
Usage: (when-let-fail b & body)
Like when-let, but fails if the binding yields a false value.