Skip to content

Instantly share code, notes, and snippets.

@minimal
Last active December 24, 2015 18:49
Show Gist options
  • Save minimal/6845185 to your computer and use it in GitHub Desktop.
Save minimal/6845185 to your computer and use it in GitHub Desktop.
(ns typed-clj-exp.core
(:require [clojure.core.typed :refer [ann check-ns typed-deps
def-alias ann-datatype for>
fn> ann-form AnyInteger doseq>
cf inst letfn> override-method
dotimes> loop>]
:as t]))
;; avoid null pointer exceptions at compile time
;; doesn't typecheck because n could be nil
(ann badincfirst [(t/Seq Number) -> Number])
#_(defn badincfirst [sq]
(let [n (first sq)]
(inc n)))
;; typechecks
(ann incfirst [(t/Seq Number) -> Number])
(defn incfirst [sq]
(let [n (first sq)]
(if n
(inc n)
1)))
;; typechecks
(+ 123 (incfirst '(1 2 3)))
;; doesn't
;; (+ 123 (incfirst '(:a)))
;; (check-ns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment