Skip to content

Instantly share code, notes, and snippets.

@fbellomi
Last active August 29, 2015 14:14
Show Gist options
  • Save fbellomi/9832211d53bd0a1dd49b to your computer and use it in GitHub Desktop.
Save fbellomi/9832211d53bd0a1dd49b to your computer and use it in GitHub Desktop.
Pretty printer for core.typed annotations
(defn pp-type [f]
(if (and (sequential? f) (<= 3 (count f)) (symbol? (first f)) (= (name (first f)) "All"))
(str "(All " (pr-str (second f)) "\n " (str/join "\n " (str/split (pp-type (nth f 2)) #"\n" )) ")")
(if (and (sequential? f) (<= 3 (count f)) (symbol? (first f)) (= (name (first f)) "IFn"))
(str "(IFn " (str/join "\n " (map pr-str (rest f))) ")")
(pr-str f))))
(defn pretty-print-type [f]
(-> (pp-type f)
(str/replace #"(clojure\.core\.typed/)|(clojure\.lang\.)|(java\.lang\.)" "")
(str/replace "(U " "(\u222a ")
(str/replace "(I " "(\u2229 ")
(str/replace "(All " "(\u2200 ")
(str/replace "(IFn " "(\u03bb ")
(str/replace " -> " " \u2192 ")
(str/replace "[-> " "[\u2192 ")
))
@fbellomi
Copy link
Author

It's the one currently used by http://crossclj.info
Some cases are not well covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment