Last active
December 24, 2015 18:49
-
-
Save minimal/6845185 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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