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
(-> (ast (letfn [(a []) | |
(b [a] a) | |
(c [c] a) | |
(a [b c] b)] | |
(a b c))) | |
ast-hy emit-hy) | |
;=> | |
((fn* ([] (letfn* [a (fn* a4844 ([] nil)) | |
b (fn* b4846 ([a4853] a4853)) | |
c (fn* c4848 ([c4854] a4843)) |
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
clojure.core.typed=> (->> (check-ns-info) :delayed-errors first ex-data) | |
{:env {:source "clojure.core.typed", :column 1, :line 53, :ns {:name clojure.core.typed}, :locals {}}, :form (def -base-aliases (quote #{EmptySeqable Vec Int NonEmptyCount Seqable NonEmptyColl Option Set NonEmptySeqable SortedSet Coll NonEmptyLazySeq Atom1 EmptyCount Map Num Seq NonEmptyVec Id AnyInteger NonEmptySeq})), :type-error :clojure.core.typed.utils/tc-error-parent} |
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
(defmacro if-every-let [bindings then else] | |
(let [[lhs rhs] bindings] | |
`(let [temp# ~rhs] | |
(if (not-any? nil? temp#) | |
(let [~lhs temp#] | |
~then) | |
~else)))) | |
; (if-every-let [foo bar] | |
; then |
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
(cf (defprotocol Foo (bar [this]))) | |
=> | |
Type Error (clojure.core.typed.test.core:1:34) Found untyped var definition: clojure.core.typed.test.core/Foo | |
Hint: Add the annotation for clojure.core.typed.test.core/Foo via check-ns or cf | |
in: (def Foo {}) | |
Type Error (clojure.core.typed.test.core:1:34) Unannotated var clojure.core/alter-meta! | |
Hint: Add the annotation for clojure.core/alter-meta! via check-ns or cf | |
in: clojure.core/alter-meta! |
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
hugod | |
is there a description somewhere of why vars need explicit annotation? | |
ambrosebs_ | |
hugod: well there's a few papers ;) | |
ambrosebs_ | |
core.typed implements local type inference, which requires lots of help at the top level. | |
ambrosebs_ | |
turns out it's powerful enough to infer locals, but not quite enough to infer local fn parameters. Definitely not powerful enough for top-levels. | |
ambrosebs_ | |
also loop variables often need annotation. |
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
clojure.core/fnil (All [x y z a b ...] | |
(Fn [[x b ... b -> a] x -> [(U nil x) b ... b -> a]] | |
[[x y b ... b -> a] x y -> [(U nil x) (U nil y) b ... b -> a]] | |
[[x y z b ... b -> a] x y z -> [(U nil x) (U nil y) (U nil z) b ... b -> a]])) |
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
(cljs.core.typed/cf | |
(defn ^{:ann '[(U nil (cljs.core/ISeqable Any)) Any -> int]} | |
index-of [xs x] | |
(let [len (count xs)] | |
(cljs.core.typed/loop> [i :- int, 0] | |
(if (< i len) | |
(if (= (nth xs i) x) | |
i | |
(recur (inc i))) | |
-1)))))) |
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
(ann ^:no-check add-datatype-ancestors [Symbol (t/Set r/TCType) -> nil]) | |
(defn add-datatype-ancestors | |
"Add a set of ancestor overrides for the datatype named sym." | |
[sym tset] | |
(assert-dt-ancestors) | |
(when-let-fail [a *current-dt-ancestors*] | |
(swap! a update-in [sym] #(set/union (or % #{}) tset))) | |
nil) | |
(defn ^:no-check ^{:ann '[Symbol (t/Set r/TCType) -> nil]} |
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
(defprotocol PMaths | |
(mult-by-two [this])) | |
(defrecord SpecialNumber [x] | |
PMaths | |
(mult-by-two [this] (assoc this :x (* (:x this) 2)))) | |
(extend-protocol PMaths | |
nil | |
(mult-by-two [this]) |
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-example.core | |
(:import (clojure.lang Symbol Seqable)) | |
(:require [clojure.core.typed :refer [ann check-ns defprotocol> ann-datatype ann-protocol inst]])) | |
(ann-protocol Similar | |
is-similar? [Similar Any -> Boolean]) | |
(defprotocol> Similar | |
(is-similar? [this a])) | |
(ann-datatype MyInt [x :- Number]) |