-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Co/contravariance for function schemas? #320
Comments
This seems right. For example, encoding a (encode [:=> [:cat string?] int?]
str->int
(function-transformer
(cat-transformer (int-transformer))
(string-transformer)))
=> (fn [& args]
(encode int?
(apply
str->int
(decode [:cat string?]
(cat-transformer (int-transformer))
args))
(string-transformer))) And decoding it back to (decode [:=> [:cat string?] int?]
int->str
(function-transformer
(cat-transformer (int-transformer))
(string-transformer)))
=> (fn [& args]
(decode int?
(apply
int->str
(encode [:cat string?]
(cat-transformer (int-transformer))
args))
(int-transformer))) This might open a can of worms wrt. performance (eg., wrapping wrappers). There are some nice papers to mitigate some of the cost, see space-efficient contracts and coercions. An example written in Clojure.
Yes, perhaps. I think something weird (unsound) needs to be done for One interesting (new) part to me is the relationship between the schemas and the transformers. I tried to write some typing rules. As you say, this seems related to coercions, which I only have a passing familiarity with.
(For those new to typing rules, read
as "if condition1 and condition2, then consequent".) |
From working on coercion subtyping I would assume that a function schema encoder would be something like
and decoder
but currently they are no-ops.
Of course type-theoretic intuitions might not translate to a dynamic language. I think function schemas are a bit weird anyway since they can only be checked by calling the function.
The text was updated successfully, but these errors were encountered: