API for clojure.core.typed - Gradual Typing 0.2.69 (in development)


Full namespace name: clojure.core.typed

Overview

This namespace contains typed wrapper macros, type aliases
and functions for type checking Clojure code. check-ns is the interface
for checking namespaces, cf for checking individual forms.

Public Variables and Functions



ASeq

type alias
Usage: (ASeq t)
A sequential seq returned from clojure.core/seq

(TFn
 [[x :variance :covariant]]
 (I
  (clojure.lang.ISeq x)
  clojure.lang.Sequential
  (Iterable x)
  (java.util.Collection x)
  (java.util.List x)
  clojure.lang.IObj))


AVec

type alias
Usage: (AVec t)
A persistent vector returned from clojure.core/vector (and others)

(TFn
 [[x :variance :covariant]]
 (I
  (clojure.lang.IPersistentVector x)
  (java.lang.Iterable x)
  (java.util.Collection x)
  (java.util.List x)
  clojure.lang.IObj))


Agent1

type alias
Usage: (Agent1 t)
An agent that can read and write type x.

(TFn [[x :variance :invariant]] (clojure.lang.Agent x x))


Agent2

type alias
Usage: (Agent2 t t)
An agent that can write type w and read type r.

(TFn
 [[w :variance :contravariant] [r :variance :covariant]]
 (clojure.lang.Agent w r))


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?

(U Integer Long clojure.lang.BigInt BigInteger Short Byte)


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.

(TFn [[x :variance :invariant]] (clojure.lang.Atom x x))


Atom2

type alias
Usage: (Atom2 t)
An atom that can write type w and read type r.

(TFn
 [[w :variance :contravariant] [r :variance :covariant]]
 (clojure.lang.Atom w r))


BlockingDeref

type alias
Usage: (BlockingDeref t)
A Clojure blocking derefable (see clojure.core/deref).

(TFn [[x :variance :covariant]] (clojure.lang.IBlockingDeref x))


Bool

type alias
Usage: Bool
A boolean

java.lang.Boolean


Coll

type alias
Usage: (Coll t)
A persistent collection with member type x.

(TFn [[x :variance :covariant]] (clojure.lang.IPersistentCollection x))


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}).

(TFn [[x :variance :covariant]] (clojure.lang.Delay x))


Deref

type alias
Usage: (Deref t)
A Clojure derefable (see clojure.core/deref).

(TFn [[x :variance :covariant]] (clojure.lang.IDeref x))


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.

(ExactCount 0)


EmptySeqable

type alias
Usage: (EmptySeqable t)
A type that can be used to create a sequence of member type x
with count 0.

(TFn
 [[x :variance :covariant]]
 (I (clojure.lang.Seqable x) (ExactCount 0)))


ExInfo

type alias
Usage: ExInfo
A Clojure custom exception type.

(I clojure.lang.IExceptionInfo RuntimeException)


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?

clojure.lang.Fn


Future

type alias
Usage: (Future t)
A Clojure future (see clojure.core/{future-call,future}).

(TFn
 [[x :variance :covariant]]
 (Extends
  [(clojure.lang.IDeref x)
   (clojure.lang.IBlockingDeref x)
   clojure.lang.IPending
   java.util.concurrent.Future]))


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.

'{:parents (clojure.lang.IPersistentMap Any Any),
  :ancestors (clojure.lang.IPersistentMap Any Any),
  :descendants (clojure.lang.IPersistentMap Any Any)}


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.

(TFn [[x :variance :covariant]] x)


Int

type alias
Usage: Int
A type that returns true for clojure.core/integer?

(U Integer Long clojure.lang.BigInt BigInteger Short Byte)


Keyword

type alias
Usage: Keyword
A keyword

clojure.lang.Keyword


Kw

type alias
Usage: Kw
A keyword

clojure.lang.Keyword


List

type alias
Usage: (List t)
A Clojure persistent list.

(TFn [[x :variance :covariant]] (clojure.lang.IPersistentList x))


Map

type alias
Usage: (Map t t)
A persistent map with keys k and vals v.

(TFn
 [[k :variance :covariant] [v :variance :covariant]]
 (clojure.lang.IPersistentMap k v))


Multi

type alias
Usage: Multi
A Clojure multimethod.

clojure.lang.MultiFn


Namespace

type alias
Usage: Namespace
A namespace

clojure.lang.Namespace


Nilable

type alias
Usage: (Nilable t)
A union of x and nil.

(TFn [[x :variance :covariant]] (U nil x))


NilableNonEmptyASeq

type alias
Usage: (NilableNonEmptyASeq t)
The result of clojure.core/seq.

(TFn
 [[x :variance :covariant]]
 (U
  nil
  (I
   (clojure.lang.ISeq x)
   clojure.lang.Sequential
   (Iterable x)
   (java.util.Collection x)
   (java.util.List x)
   clojure.lang.IObj
   (CountRange 1))))


NilableNonEmptySeq

type alias
Usage: (NilableNonEmptySeq t)
A persistent sequence of member type x with count greater than 0, or nil.

(TFn
 [[x :variance :covariant]]
 (U nil (I (clojure.lang.ISeq x) (CountRange 1))))


NonEmptyASeq

type alias
Usage: (NonEmptyASeq t)
A sequential non-empty seq retured from clojure.core/seq

(TFn
 [[x :variance :covariant]]
 (I
  (clojure.lang.ISeq x)
  clojure.lang.Sequential
  (Iterable x)
  (java.util.Collection x)
  (java.util.List x)
  clojure.lang.IObj
  (CountRange 1)))


NonEmptyAVec

type alias
Usage: (NonEmptyAVec t)
A persistent vector returned from clojure.core/vector (and others) and count greater than 0.

(TFn
 [[x :variance :covariant]]
 (I
  (clojure.lang.IPersistentVector x)
  (java.lang.Iterable x)
  (java.util.Collection x)
  (java.util.List x)
  clojure.lang.IObj
  (CountRange 1)))


NonEmptyColl

type alias
Usage: (NonEmptyColl t)
A persistent collection with member type x and count greater than 0.

(TFn
 [[x :variance :covariant]]
 (I (clojure.lang.IPersistentCollection x) (CountRange 1)))


NonEmptyCount

type alias
Usage: NonEmptyCount
The type of all things with count greater than 0. Use as part of an intersection.
eg. See NonEmptySeq

(CountRange 1)


NonEmptyLazySeq

type alias
Usage: (NonEmptyLazySeq t)
A non-empty lazy sequence of type t

(TFn
 [[t :variance :covariant]]
 (I (clojure.lang.LazySeq t) (CountRange 1)))


NonEmptySeq

type alias
Usage: (NonEmptySeq t)
A persistent sequence of member type x with count greater than 0.

(TFn
 [[x :variance :covariant]]
 (I (clojure.lang.ISeq x) (CountRange 1)))


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.

(TFn
 [[x :variance :covariant]]
 (I (clojure.lang.Seqable x) (CountRange 1)))


NonEmptyVec

type alias
Usage: (NonEmptyVec t)
A persistent vector with member type x and count greater than 0.

(TFn
 [[x :variance :covariant]]
 (I (clojure.lang.IPersistentVector x) (CountRange 1)))


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?

Number


Option

type alias
Usage: (Option t)
A union of x and nil.

(TFn [[x :variance :covariant]] (U nil x))


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}).

(TFn
 [[x :variance :invariant]]
 (Rec
  [p]
  (I
   (Extends
    [(clojure.lang.IDeref x)
     (clojure.lang.IBlockingDeref x)
     clojure.lang.IPending])
   [x -> (U nil p)])))


Proxy

type alias
Usage: Proxy
A Clojure proxy.

clojure.lang.IProxy


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.

(TFn [[x :variance :invariant]] (clojure.lang.Ref x x))


Ref2

type alias
Usage: (Ref2 w r)
A ref that can write type w and read type r.

(TFn
 [[w :variance :contravariant] [r :variance :covariant]]
 (clojure.lang.Ref w r))


Reversible

type alias
Usage: (Reversible t)
A Clojure reversible collection.

(TFn [[x :variance :covariant]] (clojure.lang.Reversible x))


Seq

type alias
Usage: (Seq t)
A persistent sequence of member type x.

(TFn [[x :variance :covariant]] (clojure.lang.ISeq x))


Seqable

type alias
Usage: (Seqable t)
A type that can be used to create a sequence of member type x.

(TFn [[x :variance :covariant]] (clojure.lang.Seqable x))


Sequential

type alias
Usage: Sequential
A sequential collection.

clojure.lang.Sequential


SequentialSeq

type alias
Usage: (SequentialSeq t)
A Clojure sequential sequence. Seq's aren't always Sequential.

(TFn
 [[x :variance :covariant]]
 (I clojure.lang.Sequential (clojure.lang.ISeq x)))


SequentialSeqable

type alias
Usage: (SequentialSeqable t)
A sequential, seqable collection. Seq's aren't always Sequential.

(TFn
 [[x :variance :covariant]]
 (I clojure.lang.Sequential (clojure.lang.Seqable x)))


Set

type alias
Usage: (Set t)
A persistent set with member type x

(TFn [[x :variance :covariant]] (clojure.lang.IPersistentSet x))


SortedSet

type alias
Usage: (SortedSet t)
A sorted persistent set with member type x

(TFn
 [[x :variance :covariant]]
 (Extends [(clojure.lang.IPersistentSet x) clojure.lang.Sorted]))


Stack

type alias
Usage: (Stack t)
A Clojure stack.

(TFn [[x :variance :covariant]] (clojure.lang.IPersistentStack x))


Str

type alias
Usage: Str
A string

java.lang.String


Sym

type alias
Usage: Sym
A symbol

clojure.lang.Symbol


Symbol

type alias
Usage: Symbol
A symbol

clojure.lang.Symbol


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.

(TFn [[x :variance :invariant]] (clojure.lang.Var x x))


Var2

type alias
Usage: (Var2 w r)
An var that can write type w and read type r.

(TFn
 [[w :variance :contravariant] [r :variance :covariant]]
 (clojure.lang.Var w r))


Vec

type alias
Usage: (Vec t)
A persistent vector with member type x.

(TFn [[x :variance :covariant]] (clojure.lang.IPersistentVector x))


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


ann-form

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


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


check-form*

var

    
Takes a (quoted) form and optional expected type syntax and
type checks the form. If expected is provided, type-provided?
must be true.
Source


check-form-info

var

    
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.
- :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.

Default return map
- :delayed-errors  A sequence of delayed errors (ex-info instances)
- :ret             TCResult inferred for the current form
Source


check-ns

var

    
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       if true, use Timbre to profile type checking. Must include
                 Timbre as a dependency.

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

var

    
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.
- :file-mapping    If true, return map provides entry :file-mapping, a hash-map
                   of (Map '{:line Int :column Int :file Str} Str).
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 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))
Source


defn

macro
Usage: (defn poly? name docstring? [param :- type *] :- type exprs*)
       (defn poly? name docstring? ([param :- type *] :- type exprs*) +)
Like defn, but with optional annotations. All annotations default to Any,
like the typed fn macro. Rest parameters default to starred.

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 ...))


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

var

    
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 ...))


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


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

var

    
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

var

    
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.
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

var

    
During type checking, print the type environment to *out*,
preceeded by literal string debug-str.
Source


print-filterset

var

    
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

var

    
Reset internal type caches.
Source


statistics

var

    
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


var-coverage

var

    
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.

clojure.core.typed.async

This namespace contains annotations and helper macros for type
checking core.async code. Ensure clojure.core.async is require'd
before performing type checking.

go
  use go

chan
  use chan

buffer
  use buffer (similar for other buffer constructors)


clojure.core.typed.base-env-common

Utilities for all implementations of the type checker


clojure.core.typed.check-form-cljs





Public Variables and Functions



check-form-cljs

function
Usage: (check-form-cljs form expected expected-provided?)
Check a single form with an optional expected type.
Intended to be called from Clojure. For evaluation at the Clojurescript
REPL see cf.
Source

clojure.core.typed.check-ns-clj





Public Variables and Functions



check-ns-info

function
Usage: (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.
- :file-mapping    If true, return map provides entry :file-mapping, a hash-map
                   of (Map '{:line Int :column Int :file Str} Str).
Source

clojure.core.typed.collect-utils





Public Variables and Functions



collect-ns*

function
Usage: (collect-ns* nsym {:keys [ast-for-ns collect-asts collect-ns]})
Collect type annotations and dependency information
for namespace symbol nsym, and recursively check 
declared typed namespace dependencies.
Source

clojure.core.typed.hole

This namespace contains easy tools for hole driven development
See also: Hole Driven Development

Types



NoisyHole

type

    Fields: []
Protocols:
Interfaces:

Public Variables and Functions



->NoisyHole

function
Usage: (->NoisyHole)
Positional factory function for class clojure.core.typed.hole.NoisyHole.
Source


noisy-hole

function
Usage: (noisy-hole)
A noisy hole. The type system will complain when
(noisy-hole) is used in positions that expect a type
more specific than Object or Any.
Use (noisy-hole) as a placeholder for code.
Throws an exception when evaluted.
Source


silent-hole

function
Usage: (silent-hole)
A silent hole. (silent-hole) passes for any other type
when type checking.
Use (silent-hole) as a placeholder for code.
Throws an exception when evaluted.
Source

clojure.core.typed.macros





Public Variables and Functions



ann-form

macro
Usage: (ann-form form ty)
Annotate a form with an expected type.
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)
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)
Source


defn

macro
Usage: (defn poly? name docstring? [param :- type *] :- type exprs*)
       (defn poly? name docstring? ([param :- type *] :- type exprs*) +)
Like defn, but with optional annotations. All annotations default to Any,
like the typed fn macro. Rest parameters default to starred.

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 ...))
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))
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 ...))
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)
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]
      ...)
Source


parse-colon

function
Usage: (parse-colon fdecl name)
Returns a vector of [provided? t args]
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)
Source


tc-ignore

macro
Usage: (tc-ignore & body)
Ignore forms in body during type checking
Source


when-let-fail

macro
Usage: (when-let-fail b & body)
Like when-let, but fails if the binding yields a false value.
Source

clojure.core.typed.statistics





Public Variables and Functions



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

clojure.core.typed.util-vars





Public Variables and Functions



*checking*

dynamic var

    
True during type checking.
Source


*trace-checker*

dynamic var

    
If true, print tracing information during type checking.
Source


*verbose-forms*

dynamic var

    
If true, print complete forms in error messages. Bind
around a type checking form like cf or check-ns.

eg.
(binding [*verbose-forms* true]
  (cf ['deep ['deep ['deep ['deep]]]] Number))
;=> <full form in error>
Source


*verbose-types*

dynamic var

    
If true, print fully qualified types in error messages
and return values. Bind around a type checking form like 
cf or check-ns.

eg. 
(binding [*verbose-types* true] 
  (cf 1 Number))
;=> java.lang.Number
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.