added more info on function schema explain:
(def MyFunctionSchema
(m/schema
[:function
[:=> [:cat :int] :int]
[:=> [:cat :int :int [:* :int]] :int]]
{::m/function-checker mg/function-checker}))
(m/explain
MyFunctionSchema
(fn
([x] x)
([x y & zs] (apply max x y zs))))
; => nil
(m/explain
MyFunctionSchema
(fn
([x] x)
([x y & zs] (str (apply max x y zs)))))
;{:schema [:function
; [:=> [:cat :int] :int]
; [:=> [:cat :int :int [:* :int]] :int]],
; :value #object[],
; :errors (#Error{:path [],
; :in [],
; :schema [:function
; [:=> [:cat :int] :int]
; [:=> [:cat :int :int [:* :int]] :int]],
; :value #object[],
; :check ({:total-nodes-visited 2,
; :depth 1,
; :pass? false,
; :result false,
; :result-data nil,
; :time-shrinking-ms 0,
; :smallest [(0 0)],
; :malli.generator/explain-output {:schema :int,
; :value "0",
; :errors (#Error{:path []
; :in []
; :schema :int
; :value "0"})}})})}
really happy how good the function schemas are now, but still - it’s just elegant (and slow) way to verify things at runtime, e.g. not a type system.
in master
compared to clojure.spec, how slow?
the sequence schemas are at least an order of magnitude faster than spec in initial tests. Full function verification uses test.check, I think that dominates, and quess they are about the same.
but, having arity info available for fn
s at runtime (in clojure.core) would help to see that fns are correct on arity, without testing it and getting arityexceptions - costs a lot.
Maybe you can combine that with static analysis (e.g. from clj-kondo)?
I guess it could be done using a clj-kondo hook? with defaults, the test.check runs 19ms for a function on my machine. that’s 500 funcs per sec (on 1 core?). errors are faster, the given example fails fast on invalid return, under 1ms.
i believe it could be made faster, less iterations on arguments etc.
[metosin/malli "0.3.0-SNAPSHOT"]
has the stuff in.
with 10 iterations, it drops to 0.3ms per fn.'
I mean: > but, having arity info available for fns at runtime (in clojure.core) would help to see that fns are correct on arity, without testing it and getting arityexceptions - costs a lot. You could use clj-kondo to find the correct arities perhaps
> e.g. not a type system.
i mean
for me, it would serve much the same purpose i'd think
or rather - the same workflow
maybe i'm missing a worldview though
Btw, this sounds interesting, but I haven't heard anything about it yet: https://www.fulcrologic.com/copilot