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

Make generate and lhs-indexing work for infinite sequences indexed by Integer. #1063

Closed
brianhuffman opened this issue Feb 5, 2021 · 2 comments · Fixed by #1085
Closed
Labels
language Changes or extensions to the language

Comments

@brianhuffman
Copy link
Contributor

Currently generate, which is used for lhs-indexing syntactic sugar, can only be used for finite lists of length at least 1:

Cryptol> :? generate

    generate : {n, a, ix} (fin n, n >= 1, Integral ix,
                           Literal (n - 1) ix) =>
                 (ix -> a) -> [n]a

Produce a sequence using a generating function.
Satisfies 'generate f @ i == f i' for all 'i' between '0' and 'n-1'.

Declarations of the form 'x @ i = e' are syntactic sugar for
'x = generate (\i -> e)'.

It would be nice if we could use it for lists of any length, specifically for infinite sequences which could be indexed by an Integer. Being able to define zero-length sequences would be useful too, e.g. for defining sequences that are polymorphic in the length.

Implementing this will probably require adding a new type predicate as a constraint.

@weaversa
Copy link
Collaborator

weaversa commented Feb 5, 2021

While I wholeheartedly agree generate should be more general, I think we considered this is #848 and couldn't figure out a way to do it.

@brianhuffman
Copy link
Contributor Author

I think #973 is closely related to this one. If we had a way to write [0..<n] for a list of length n, and it worked even when n is 0 or inf, then we could use that to define generate as generate f = [ f i | i <- [0 .. <n] ].

Actually, I suppose we could define generate as generate f = [ f i | i <- take`{n} [0...] ], but that would have a type that is a little more general than we really want: It is nice if the type of generate can prevent you from choosing an index type that is too small and wraps around before you get to the end of the list.

@robdockins robdockins added the language Changes or extensions to the language label Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes or extensions to the language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants