Skip to content
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

Element type constraints for sequence enumerations #625

Closed
brianhuffman opened this issue Jun 25, 2019 · 3 comments · Fixed by #806
Closed

Element type constraints for sequence enumerations #625

brianhuffman opened this issue Jun 25, 2019 · 3 comments · Fixed by #806
Assignees
Labels
docs LaTeX, markdown, literate haskell, or in-REPL documentation language Changes or extensions to the language
Milestone

Comments

@brianhuffman
Copy link
Contributor

When you write a finite list enumeration like [5 .. 10], the result has a polymorphic type:

Cryptol> :t [5..10]
[5 .. 10] : {a} (Literal 10 a) => [6]a

It would be nice if we could put a type ascription for the element type inside the brackets, like [5 .. 10:[8]]. But currently this doesn't work:

Cryptol> [5 .. 10:[8]]

Parse error at <interactive>:1:7--1:13
  The boundaries of .. sequences should be valid numeric types.
The expression `10 : [8]` is not.

If you were trying to specify the width of the elements,
you may add a type annotation outside the sequence. For example:
   [ 1 .. 10 ] : [_][16]

We should add support in the parser to allow [m .. n : t] (and also [m : t .. n]) as special syntactic forms. They would both desugar to fromTo`{first=m, last=n, a=t}.

We should similarly add support for fromThenTo enumerations, like [a, b .. c : t].

@brianhuffman brianhuffman added the language Changes or extensions to the language label Jun 25, 2019
@brianhuffman brianhuffman mentioned this issue Jun 27, 2019
@brianhuffman
Copy link
Contributor Author

Pull request #628 implements the type-annotation-on-list-bounds feature mentioned above. We should probably also document the feature before closing the ticket.

@brianhuffman
Copy link
Contributor Author

brianhuffman commented Jun 28, 2019

We might also consider extending this feature so that, e.g. ['a' .. 'z'] (see #622) gets its element type constrained to [8]. The idea is that on the value level, 'a' is basically syntactic sugar for 97:[8], so maybe it should work like that as a list enumeration bound. Similarly, a hex number like 0x1000 is basically sugar for 4096:[16], so maybe [0x1000..0x17ff] should be constrained to an element type of [16]. What does everyone think?

@brianhuffman brianhuffman added the docs LaTeX, markdown, literate haskell, or in-REPL documentation label Oct 26, 2019
@robdockins
Copy link
Contributor

We should probably actually document this somewhere before the 2.9.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs LaTeX, markdown, literate haskell, or in-REPL documentation language Changes or extensions to the language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants