plumatic / plumbing

Prismatic's Clojure(Script) utility belt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compile Time Schema Checks

saulshanabrook opened this issue · comments

It seems like right now the Graph library will not validate the schemas of the nodes at compile time, to make sure they are compatible. For example, this does not fail to compile, when schema validation is enabled, but does fail to run:

(g/compile {:takes-a (p/fnk [a :- s/Int] a)
                   :a (p/fnk returns-a :- s/Str [] "hey")})

Having this fail early would make it clear the the failure was in the schemas, not somewhere in the code.

Since each fnk has a schema for input and output, it seems like it could check that the output type of one node is compatible with all the input nodes that require it.

However, it seems like, at this time, the schema library can't check if two schemas are compatible with each other, only if a value is compatible with a schema.

Thanks for the suggestion. Graph already does do all the checking it can
on map structures, and there's an explicit "punt" on other cases such as
the one you mention.

https://github.com/plumatic/plumbing/blob/master/src/plumbing/fnk/schema.cljx#L66

Note that full compile-time type checking for arbitrary schemas is
undecidable. In a perfect world, Graph might error on examples like yours
where it's easy to prove the code is incorrect; but this is really beyond
the scope of what can be handled within this library.

If you want to pursue compile-time checks, I would recommend looking into
core.typed, and potentially converting schemas into core.typed assertions
and using its machinery to try to prove entailment or non-entailment. If
such a library existed and worked well, we would be open to providing a
hook to use it when compiling a graph -- but it's not something we have the
resources to work on ourselves, or which we think would likely be
appropriate for inclusion into the core plumbing or schema libraries (since
it would likely introduce additional dependencies, and add a lot of
complexity that is largely orthogonal to the current concerns of these
libraries).

Does that make sense?

On Sat, Feb 27, 2016 at 6:42 PM Saul Shanabrook notifications@github.com
wrote:

It seems like right now the Graph library will not validate the schemas of
the nodes at compile time, to make sure they are compatible. For example,
this does not fail to compile, when schema validation is enabled, but does
fail to run:

(g/compile {:takes-a (p/fnk [a :- s/Int] a)
:a (p/fnk returns-a :- s/Str [] "hey")})

Having this fail early would make it clear the the failure was in the
schemas, not somewhere in the code.

Since each fnk has a schema for input and output, it seems like it could
check that the output type of one node is compatible with all the input
nodes that require it.

However, it seems like, at this time, the schema library can't check if
two schemas are compatible with each other, only if a value is compatible
with a schema.


Reply to this email directly or view it on GitHub
#116.

Yeah that does make sense. I likely won't touch it for now, but if I implement anything I will post it here.

Thank you for the explanation.

Sounds good, thanks!

On Mon, Feb 29, 2016 at 1:44 AM Saul Shanabrook notifications@github.com
wrote:

Yeah that does make sense. I likely won't touch it for now, but if I
implement anything I will post it here.

Thank you for the explanation.


Reply to this email directly or view it on GitHub
#116 (comment).