-
Notifications
You must be signed in to change notification settings - Fork 98
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
Opt-in static typing globally #2049
Comments
There's one remaining question though, if your use-case is really to prevent people from circumventing static typing. In Nickel, a contract annotation disables typechecking locally (cf relevant section of the manual). This means that writing One possibility is to have several levels of enforcement, and one where no matter what happens, any piece of code is always statically typechecked. But this might prove to be harder to use, because the language wasn't built with that idea in mind (some stdlib functions could be difficult to use, for example - see #2050). It really depends on the complexity of the configuration, though - in practice, most standard functions are entirely fine and the statically typed core should be as powerful as any basic functional language out there. And there are solutions (basically have a different, better-typed interface for some of those functions) as mentioned in #2050, and having such a strict typechecking mode could be a motivation to try to implement them. In any case, most statically typed languages have escape hatch - Another noteworthy point is that merging isn't statically typed currently either (this isn't necessarily impossible in theory, but it needs a non trivial evolution of the type system and some prior design work). Though if the merging happens on the CLI - you just write a bunch of As a side note, while static typing is really nice for functions, I think you can go very far (and actually farther than static typing for some properties) with proper contracts for your configuration data. You can run |
(As another illustration of the "contract annotations disable typechecking" issue, someone could just take a whole |
for I would be satisfied if it required removing or adding some obvious thing in order to disable typechecking so it would be hard to get through review (removing some |
It's not useful to the conversation, but just because I wanted to write down this heresy, you can actually do very dirty things with unsafe 😈 let x : u32 = unsafe { std::mem::transmute::<[bool; 4], u32>([true, true, false, false]) }; On a more serious note, I agree. I propose to start with a We can always revisit later and add the stricter level where everything has to be typed, even under contract annotations, if ever needed. Both shouldn't be hard to implement at all; the only question is if the second level would is usable and thus useful in practice. |
Is your feature request related to a problem? Please describe.
My team is considering using Nickel for our config language, but we really like static typing, and want to make sure it is enforced when people outside of our immediate team try to change stuff. We would like a way to opt-in to enforce static typing globally, so for example we can have CI type-check the config and "you shall not pass" people if it doesn't check out.
Describe the solution you'd like
A simple solution is to just have a CLI flag to opt-in
Describe alternatives you've considered
Another idea that has been floated is to have a per-file pragma, but this might allow people to comment that out in a moment of frustration and still be able to merge.
Additional context
This idea was originally discussed on the Discord: https://discord.com/channels/1174731094726295632/1179430745727586407/1285771238618435605 (and following replies)
The text was updated successfully, but these errors were encountered: