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

public/private with no indentation #1180

Open
yav opened this issue Apr 23, 2021 · 1 comment
Open

public/private with no indentation #1180

yav opened this issue Apr 23, 2021 · 1 comment
Labels
design needed We need to specify precisely what we want language Changes or extensions to the language parser Issues with lexing or parsing.

Comments

@yav
Copy link
Member

yav commented Apr 23, 2021

Currently public and private blocks require indentation of the declarations containing them, which can be a bit annoying if one has a lot of private declarations. With the changes in #1179 one could put all private declarations at the end of the file, but that's still a bit awkward.

It doesn't really make sense to nest public and private blocks, so here are a few ways to make code like this work:

x = 0x2

private
y = 0x3

public
z = 0x3

One option would be to treat public/private not as a layout starting construct, but as a top-level declaration, with the meaning that the following declarations are public or private. This is simple, but unfortunately is not backward compatible, as if one did indent the declarations (as it is done in current code), things would break---now there is no layout block, so no semis will be added in the right places.

Another way would be to keep public and private as layout starting constructs, but modify the parser to allow nesting them. The idea is that after parsing we'd flatten the nested declarations into a list, which would match the order of declarations of the file. This (assuming the fix suggested in #1179) is, I think, a backward compatible way to support piblic/pribate without the need for indentation.

@yav yav added language Changes or extensions to the language parser Issues with lexing or parsing. labels Apr 23, 2021
@robdockins
Copy link
Contributor

The idea of nesting public/private blocks together makes sense to me (with the innermost property taking effect). I don't know enough about the exact details of the layout rules to have an opinion on how to structure things, but I like the idea that you could do things like the following to invert the usual visibility rules, if desired:

module SomeStuff where private

public
  hereIsTheAPI = ...

myPrivateImplementation = ....

I think I also like the idea of public/private as a declaration modifier, but I think it's even stronger with an idea I'll call "conditional block heralds", which only start a block if they are the last token on a line. Then we could use these for "public" "private" and "property", with the additional rule that they are allowed to modify other single declaration. I think this would be mostly backward-compatible, and let use use the keywords in new ways too. This would help us with #331, as well as the issue below I noted with modules:

private module A where
  x = 42

@kquick kquick changed the title piblic/private with no indentation public/private with no indentation Apr 23, 2021
@yav yav added the design needed We need to specify precisely what we want label Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design needed We need to specify precisely what we want language Changes or extensions to the language parser Issues with lexing or parsing.
Projects
None yet
Development

No branches or pull requests

2 participants