Giter VIP home page Giter VIP logo

Comments (2)

yannham avatar yannham commented on May 26, 2024

There are different ways to go about this, but note that in general checking a local contract might require values from the outer scope, or even values that aren't known at writing time (such as inputs of the configuration).

One way could be to try to evaluate the expression, and just ignore any error that isn't a contract error (such as missing field, or even just classify errors that should be reported immediately versus the ones that could stem from evaluating just a fragment of the program).

Another possibility, for simple cases, could be to try to infer a type for the subexpression, and compare that to basic contracts - if it fails to typecheck, we can't say anything, but if it succeeds with a type that is incompatible with the contract, then there is a problem. Both approaches (and there's probably more, such as just running the full program and reporting any error on command) have different trade-offs:

  • Tthe partial evaluation one is simple and generic, and handle custom contracts, but can't handle unknown inputs (i.e won't report obviously wrong things such as { foo | Number, bar | String = foo ++ "a"})
  • The typing approach can't handle custom contract, and can't handle ill-typed terms (that aren't necessarily wrong, just not accepted by the static typechecker), but better handles incomplete values.

Or maybe we can combine both?

from nickel.

yannham avatar yannham commented on May 26, 2024

I believe this is closed by the same PR as #1586, giving stuff like this in practice:

image

Feel free to re-open, or open new issues for more specific aspects of in-code contract evaluation.

from nickel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.