-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
New Some
/None
constructors for Optional
values
#227
Conversation
... as discussed in #113 (comment) This adds new `Some`/`None` constructors that will (eventually) displace the `List`-like syntax for `Optional` values. This proposes that `Some`/`None` are the new normal forms for optional literals and that the legacy `List`-like syntax β-normalizes to `Some`/`None`. The reason why is that converting in the opposite direction from `Some t` to `[ t ] : Optional T` would require performing type inference during β-normalization (which would complicate β-normalization). In contrast, converting from `[ t ] : Optional T` is straightforward and only requires dropping the type. Eventually the legacy `List`-like syntax will be dropped after a suitably long migration period.
standard/binary.md
Outdated
|
||
|
||
encode-1.0(t₀) = t₁ encode-1.0(T₀) = T₁ | ||
──────────────────────────────────────────────── | ||
encode-1.0([ t₀ ] : Optional T₀) = [ 5, T₁, t₁ ] | ||
|
||
|
||
encode-1.0(t₀) = t₁ | ||
───────────────────────────────────── | ||
encode-1.0(Some t₀) = [ 5, null, t₁ ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decoding judgement will need to learn about the null
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, whoops, yes. I also forgot to bump the protocol version string to "1.1"
and other related changes
This sounds wonderful! It would simplify the parser as well :) |
... as standardized in dhall-lang/dhall-lang#227 The legacy `Optional` syntax is still supported for now but the normal form for `Optional` literals now prefers `Some`/`None`. The `dhall lint` command will automatically migrate the old `Optional` literal syntax to the new syntax.
Here's the matching pull request for the Haskell implementation: dhall-lang/dhall-haskell#559 |
@Gabriel439 this is cool 👏 👏 About your concerns in #113 (comment):
Then I have a couple of questions on the PR itself:
|
I'd point out that Present is also a verb (to present) which could be
confusing if someone thought it was a method call.
…On Sat, 1 Sep 2018, 8:08 pm Fabrizio Ferrai, ***@***.***> wrote:
@Gabriel439 <https://github.com/Gabriel439> this is cool 👏 👏
About your concerns in #113 (comment)
<#113 (comment)>
:
- Present/Absent: I agree with your analysis but I think it presents
more compelling reasons to go with Some/None rather than with
Present/Absent:
1. shorter to type - I type them a lot and the reason why the
current syntax is bothersome to me is mostly because it's a lot of chars
2. they are already used in other langs (Rust, Scala, probably
others), so more familiar to their userbase (which I think massively
overlaps with our most-likely-to-be userbase)
- Some/None vs some/none: I'd classify them as "constructors" instead
of "keyword"; now, in Dhall we don't have prior cases of "constructors"
that we can refer to (as there is just special syntax to construct all
other built-in values), but constructors are usually capitalized (in any
language I can think of), so Some/None feels right
Then I have a couple of questions on the PR itself:
- Having to do a massive replacing for the protocol version string
every time we add an AST constructor is a lot of work. Would it be possible
to call the encoding function just encode and then say "we specify
encode for the latest version X.Y", and then specify a version only
when specifying the encoding for cases in any other version than the latest?
- If we normalize to the new Some/None (which is good) would this mean
that when caching hash-protected imports the old [ .. ] : Optional ..
form will not be present anymore? (since IIRC we beta-normalize imports
before writing them to the cache)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#227 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABRjs_-zIeIUU9WC-bPXj93WKhSNnfQks5uWtszgaJpZM4WWFp->
.
|
@f-f: Yeah, I'm warming up to
Sure, I will just use
Yes. New cached values will now store |
Much as I'm not thrilled about Too bad AfC |
... as suggested by @f-f
... as standardized in dhall-lang/dhall-lang#227 The legacy `Optional` syntax is still supported for now but the normal form for `Optional` literals now prefers `Some`/`None`. The `dhall lint` command will automatically migrate the old `Optional` literal syntax to the new syntax.
... as discussed in #113 (comment)
This adds new
Some
/None
constructors that will (eventually) displace theList
-like syntax forOptional
values.The key new feature is that
Some
does not require you to supply the elementtype. In other words, you can now write
Some 1
instead of[ 1 ] : Optional Integer
.The second benefit is that the new constructors are just shorter in general.
This proposes that
Some
/None
are the new normal forms for optional literalsand that the legacy
List
-like syntax β-normalizes toSome
/None
. Thereason why is that converting in the opposite direction from
Some t
to[ t ] : Optional T
would require performing type inference duringβ-normalization (which would complicate β-normalization). In contrast,
converting from
[ t ] : Optional T
is straightforward and only requiresdropping the type.
Eventually the legacy
List
-like syntax will be dropped after a suitablylong migration period.