-
Notifications
You must be signed in to change notification settings - Fork 90
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
The Syntax Bikeshedding Dojo, round 1: Typing (Assume/Promise) #183
Comments
Some additional helpful context: Can you estimate how (relative) frequently each of these annotations will occur? In particular, if dynamic is not ubiquitous, then I might suggest no operator for it and using only keywords instead. I'm admittedly steeped in Haskell at this point, but my immediate instinct is that I had considered I would vote against (the current motivation for) HTH. Good luck. |
Good question. My take is:
To sum up, I expect |
After a bit more thinking, this is also a good remark. In particular, we may make use of static coercions to be able to convert a static record type |
A bit more widely used operator for type casting is the |
This is a bit of an aside, but I'd like this terminology not to become part of the user-facing documentation. I don't think that they represent very well what's happening (i.e. looking for something to typecheck, and typechecking, respectively).
I thought Haskell's Some proposals.
As for assert: it is a form of a type-cast: from |
It occurs to me, in light of #187 , that we can have attributes on lets as well. And
Can also act as assert. |
This looks very close to
I suppose so, this would be the type inferred by the typechecker. We have to exclude polymorphic types, or at least rank-N types as well as the Dyn type. But not having studied formally the current type system, this is just a supposition.
I really like the idea, this looks good and makes the notation coherent with meta-values, which have precisely the same semantics. But I would prefer to keep the "= term" part, otherwise this would be confusing to go from
|
The time has come to have a presentable syntax, if not sexy. The first target of this grand bikeshedding festival is typing annotations.
Context
In Nickel, typing is controlled via two dual constructs:
Promise(type, term)
andAssume(type, term)
. They both have a static semantics, during the typechecking phase, and a dynamic semantics, during execution. Since the type system is gradual, the typechecker features two different modes:The aforementioned constructs serve as annotations, but also toggle the typechecker mode.
Static semantics
Promise(type, term)
delimits a term that must be statically checked. The typechecker enters in strict mode, and checksterm
againsttype
.Assume(type, term)
, on the contrary, tells the typechecker "trust me on this one". The term is blindly accepted to have typetype
, and is not statically checked. The typechecker enters in non-strict mode.Dynamic semantics
At run-time, both constructs evaluate to the same run-time check, that is that
term
indeed evaluates to a value of typetype
, but for slightly different reasons:term
indeed evaluates to a value of typetype
, without needing to check it again at run-time. While this is true for base types, there is an issue with higher-order types: a typed function can be called from untyped code. In particular, it can be passed arguments of the wrong type: the role of the run-time check is then to reject such calls by checking each argument, instead of raising a type mismatch error inside a seemingly well-typed function.Assume(type, term)
is blindly trusted during typechecking, butterm
could very well be of the wrong type. To verify thatterm
lives up to its expectations, a run-time check is inserted.Proposal
Just to start the discussion.
Promise
Promise
would become a type annotation on a let-binding:Assume
Assume
can be thought of as a type coercion, or a type cast (the actual name in the gradual typing literature), in that it converts a term to an arbitrary type during typechecking. We can use the:>
operator, used in OCaml for type coercions.Pros
:
is used everywhere and usually relates to static typing.:>
conveys the static semantics ofAssume
, which I find is emphasized by the asymmetry of the operator: the term is cast to a target type.Cons
Assume
andPromise
are not only annotations, they also delimit zones for typechecking, namely typed and untyped. Maybe we could use a syntax which makes this clearer (enclose the term between delimiters ?):>
is specific to OCaml or comes from another language, but it is probably not that mainstream.The text was updated successfully, but these errors were encountered: