{"id":19917202,"url":"https://github.com/athos/type-infer","last_synced_at":"2025-07-09T05:35:45.268Z","repository":{"id":62435048,"uuid":"333463764","full_name":"athos/type-infer","owner":"athos","description":"A Clojure utility to inspect static types inferred by the Clojure compiler","archived":false,"fork":false,"pushed_at":"2023-08-22T16:21:43.000Z","size":34,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T12:57:59.548Z","etag":null,"topics":["clojure","macros","static-types","type-inference"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-27T15:18:15.000Z","updated_at":"2025-02-27T13:29:29.000Z","dependencies_parsed_at":"2024-11-12T21:49:15.532Z","dependency_job_id":"b2553e6a-cd37-4745-ab5a-4072a962a1e1","html_url":"https://github.com/athos/type-infer","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"350a248817c94f122b3f83ffdeadb23b5445a383"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Ftype-infer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Ftype-infer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Ftype-infer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athos%2Ftype-infer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athos","download_url":"https://codeload.github.com/athos/type-infer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252154732,"owners_count":21702982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","macros","static-types","type-inference"],"created_at":"2024-11-12T21:49:08.599Z","updated_at":"2025-05-03T06:30:46.852Z","avatar_url":"https://github.com/athos.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-infer\n[![Clojars Project](https://img.shields.io/clojars/v/dev.athos/type-infer.svg)](https://clojars.org/dev.athos/type-infer)\n![build](https://github.com/athos/type-infer/workflows/build/badge.svg)\n\nA Clojure utility to inspect static types inferred by the Clojure compiler\n\n## Installation\n\nAdd the following to your `deps.edn` / `project.clj`:\n\n- `deps.edn`\n```\n{dev.athos/type-infer {:mvn/version \"0.1.2\"}}\n```\n\n- `project.clj`\n```\n[dev.athos/type-infer \"0.1.2\"]\n```\n\n## Usage\n\n### `infer`\n\nThe `infer` macro tells us the static type of the given expression inferred\nby the Clojure compiler:\n\n```clojure\n(require '[type-infer.core :refer [infer]])\n\n(infer 42) ;=\u003e long\n(infer false) ;=\u003e java.lang.Boolean\n(infer \"foo\") ;=\u003e java.lang.String\n```\n\nIt can take an arbitrary expression and returns its static type as long as \nthe Clojure compiler can infer:\n\n```clojure\n(infer (not false)) ;=\u003e java.lang.Boolean\n(infer (/ 1 2)) ;=\u003e java.lang.Number\n(infer (if (even? 2) :even :odd)) ;=\u003e clojure.lang.Keyword\n(infer (let [x 2 y (inc x)] (* x y))) ;=\u003e long\n(infer (fn [x] x)) ;=\u003e clojure.lang.AFunction\n```\n\nOtherwise (i.e. the compiler failed to infer the static type of the given expression),\n`infer` returns `nil`:\n\n```clojure\n(infer (identity 42)) ;=\u003e nil\n(infer (if (even? 2) \"foo\" false)) ;=\u003e nil\n(infer cons) ;=\u003e nil\n```\n\nThe `infer` macro is mainly intended to be used for performance tuning, and is especially\nuseful for removing reflection warnings and taking full advantage of primitive types.\n\nIn most cases, `infer` per se is difficult to use in your function or macro.\nIf you want to use it in your macro, it's highly recommend to use `infer-type` below instead.\n\n### `infer-type`\n\nThe `infer-type` fn takes two arguments: The first one is the implicit macro argument\n`\u0026env` and the second one is a symbol. To get `\u0026env`, you need to call `infer-type` in a macro:\n\n```clojure\n(require '[type-infer.core :as ty])\n\n(defmacro my-infer-type* [sym]\n  (ty/infer-type \u0026env sym))\n \n(def ^String s \"foo\")\n(my-infer-type s) ;=\u003e java.lang.String\n\n(let [x 42]\n  (my-infer-type x)) ;=\u003e long\n```\n\nNote that `infer-type` only accepts a symbol as its second argument.\nIf you want to pass arbitrary expression to it, you'll need to pass the expression\nvia an extra `let` form like the following:\n\n```clojure\n(defmacro my-infer-type [x]\n  `(let [x# ~x]\n     (my-infer-type* x#)))\n\n(my-infer-type (fn [x] x)) ;=\u003e clojure.lang.AFunction\n```\n\nNote also that due to the above limitation, the target expression of the type inference\nmay be evaluated at most once. This means that it is impossible (or difficult at best)\nto implement macros using `infer-type` such that the input expression is never evaluated\nin the expanded form.\n\n## Practical use\n\nExamples of practical use of the library can be found in the following projects:\n\n- [sweet-array](https://github.com/athos/sweet-array)\n- [power-dot](https://github.com/athos/power-dot)\n\n## License\n\nCopyright © 2021 Shogo Ohta\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathos%2Ftype-infer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathos%2Ftype-infer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathos%2Ftype-infer/lists"}