malli icon indicating copy to clipboard operation
malli copied to clipboard

schema inference from source code

Open xificurC opened this issue 5 years ago • 6 comments

Schema providers can take sample input and generate a schema. How magical would it be if one could infer a schema from code?

(defn-magic foo [m] (+ (:x m) (-> m :y :yy)))
;; => [:map [:x number?] [:y [:map [:yy number?]]]]

I think this could be done by code-walking or something similar. If done right I think this would be invaluable, we'd get type-inference-like capabilities in the language :)

xificurC avatar Feb 20 '20 11:02 xificurC

Tools like clj-kondo and core.typed are both actively developed, I think this falls into scope of those libs. Plan is to integrate malli with clj-kondo later anyway.

ikitommi avatar Feb 21 '20 14:02 ikitommi

clj-kondo integration might be quite a killer feature!

piotr-yuxuan avatar Feb 22 '20 15:02 piotr-yuxuan

WIP. clj-kondo

ikitommi avatar Mar 07 '20 12:03 ikitommi

Apparently Typed Clojure can automagically infer Specs.

nilern avatar Jan 27 '21 10:01 nilern

malli.typed ?

ikitommi avatar Jan 27 '21 13:01 ikitommi

Unfortunately, Typed Clojure can only infer specs from data (not code), like malli does :) It instruments your code and then runs your tests.

It does some fancy things around deciding whether something is a multispec, but that's about it.

frenchy64 avatar May 27 '21 05:05 frenchy64