clojure.core.typed.impl

ann

(ann 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. Supports namespace aliases and fully qualified namespaces
to annotate vars in other namespaces.

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

ann-datatype

(ann-datatype)
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)])

ann-interface

(ann-interface args)
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]))

ann-many

(ann-many t vs)
Annotate several vars with type t.

eg. (ann-many FakeSearch
              web1 web2 image1 image2 video1 video2)

ann-protocol

(ann-protocol)
Annotate a possibly polymorphic protocol var with method types.

eg. (ann-protocol IFoo
      bar
      (IFn [IFoo -> Any]
           [IFoo Number Symbol -> Any])
      baz
      [IFoo Number -> Number])
    (t/tc-ignore
      (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
      (IFn [(IFooPoly x) -> Any]
           [(IFooPoly x) Number Symbol -> Any])
      baz
      [(IFooPoly x) Number -> Number])
    (t/tc-ignore
      (defprotocol IFooPoly
        (bar [this] [this n s])
        (baz [this n])))

ann-record

(ann-record)
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)])

cast

(cast 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)

declare-alias-kind

(declare-alias-kind sym ty)
Declare a kind for an alias, similar to declare but on the kind level.

declare-datatypes

(declare-datatypes syms)
Declare datatypes, similar to declare but on the type level.

declare-names

(declare-names syms)
Declare names, similar to declare but on the type level.

declare-protocols

(declare-protocols syms)
Declare protocols, similar to declare but on the type level.

defalias

(defalias doc-str t)(defalias t)
Define a recursive type alias on a qualified symbol. 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}))

dotimes

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

envs

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

letfn>

(letfn> fn-specs-and-annotations body)
Like letfn, but each function spec must be annotated.

eg. (letfn> [a :- [Number -> Number]
             (a [b] 2)

             c :- [Symbol -> nil]
             (c [s] nil)]
      ...)

load-if-needed

(load-if-needed)
Load and initialize all of core.typed if not already

method-type

(method-type mname)
Given a method symbol, print the core.typed types assigned to it.
Intended for use at the REPL.

nilable-param

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

non-nil-return

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

override-constructor

(override-constructor typesyn)
Override all constructors for Class ctorsym with type.

override-method

(override-method 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).

pred

(pred)
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

register!

(register!)
Internal -- Do not use

statistics

(statistics nsyms)
Takes a collection of namespace symbols and returns a map mapping the namespace
symbols to a map of data

untyped-var

(untyped-var typesyn)
Check a given var has the specified type at runtime.

var-coverage

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

warn-on-unannotated-vars

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

with-current-location

(with-current-location opts form)(with-current-location opts line col)