Giter Site home page Giter Site logo

Checking records about nickel HOT 5 CLOSED

tweag avatar tweag commented on May 19, 2024
Checking records

from nickel.

Comments (5)

thufschmitt avatar thufschmitt commented on May 19, 2024 1

Just a couple of side remarks:

  • {a: Num, b: String, _ : Bool} isn't valid in Nix since records are always finite (unless _: Bool also allows the fields to be missing)

  • You can also pattern match on optional fields like

    let f = { x ? 4 }: x+1; in
    f { x=5; } + f {}

    I guess the framework should handle these (which can be done fairly easily if you have the Δ contract, not sure otherwise)

from nickel.

teofr avatar teofr commented on May 19, 2024

since records are always finite (unless _: Bool also allows the fields to be missing)

Yeah, I'd say that _ : Bool allows the field to be missing. I guess the reason of saying _ : Bool U Δ is that the type information is forwarded, and you can force to use an or at the type level, right?

which can be done fairly easily if you have the Δ contract

That's true if you also have union types, we're putting that on standby for the moment being. So maybe having ? as a primitive

from nickel.

thufschmitt avatar thufschmitt commented on May 19, 2024

I guess the reason of saying _ : Bool U Δ is that the type information is forwarded, and you can force to use an or at the type level, right?

Not sure I understand what you mean. The reason we had that is just that it made everything more consistent (because that way _ : A is just an shortcut for forall x. x: A), but since it can always be used when the type contains Δ it's also sensible to imply it.

That's true if you also have union types, we're putting that on standby for the moment being. So maybe having ? as a primitive

Oh yes, I didn't follow that part. Then yes, you probably need something like a x :? Bool construct to replace x : Bool \/ Δ

from nickel.

teofr avatar teofr commented on May 19, 2024

Regarding Flow

Flow is Facebook's answer to typing JS (the main difference with TypeScript is that is not a different language, and is designed to be used with JavaScript's code "out of the box", but I'm not an expert on either). They have Object type, which are more or less what we want.

They have a bunch of stuff that is of interest to us:

  • Optional fields
  • They have open and close records (unsealed and sealed) with regards to usability:
    • sealed know all of its fields, and every access is checked,
    • unsealed objects sometimes can check if an access is safe, but it's usually considered unsafe
  • They also have a notion of exact objects, where only an object with exactly those fields matches. This is what we consider a close record.
  • Lastly, there is an "indexer property", that is similar to the catch all idea presented above, it let's you use an object as a map/dictionary.

Main differences (or stuff we don't really care):

  • Objects are modifiable

I think their development is quite similar to the idea of having a catch all case, and a special type stating that field doesn't exist. Their difference with unsealed and indexed objects is because Objects may grow and shrink during execution, I don't think we need to make this difference. I'll keep looking into their stuff, but this is just to have an idea of what a good set of capabilities might be, and there doesn't seem to be anything too different from the previous set of thoughts.

from nickel.

yannham avatar yannham commented on May 19, 2024

Closing old stale issue. Ideas mostly implemented (see #158).

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.