Open pchiusano opened 5 years ago
Cool!!
Side note: let's have the user config file and the codebase dirs have different names; they shouldn't both be .unison
@pchiusano
-- Pretty (ColorText, Ann) means we can add location-based highlighting after the fact
?
Using Pretty.map, you can map over the segments of the Pretty. If those segments know their location, you can pick different colors for each location. This could be used for highlighting portions of a type in type error messages, for instance.
I think this is a fantastic idea, which would bring two benefits:
A possible preparation step for this would be to move all parsing and printing code into the new Unison.Syntax.*
hierarchy. Unison.Syntax
itself would expose the fields you listed above, but as functions instead of fields (parseFile
, prettyTerm
, etc). That would be the only module from Unison.Syntax.*
the rest of the code is allowed to import.
Then when we actually add a second syntax, we could take the final step of reifying that interface into the record you describe and plumbing it around.
What do you think? Do you think my intermediate suggestion would be a good incremental goal, or should we go ahead and both separate out the syntax code and plumb the record through at the same time?
I'm not totally sure what would be the easiest refactor. However, at the moment I'm doing surgery on the lexer and parser to support the new documentation format, so I'd probably hold off on refactoring until after that merges. (I'm hoping in next few weeks)
Sounds good to me!
I could be wrong, but I think it will be hard to even find all of the parsing and printing code unless we are trying to plumb the record through. There are some little bits scattered around, inlined, etc.
I could be wrong, but I think it will be hard to even find all of the parsing and printing code unless we are trying to plumb the record through. There are some little bits scattered around, inlined, etc.
@aryairani Great point, though on the other hand anything we can do to split this into separate PRs is going to help.
However, at the moment I'm doing surgery on the lexer and parser to support the new documentation format, so I'd probably hold off on refactoring until after that merges. (I'm hoping in next few weeks)
@pchiusano: How's that coming along? Also is there an issue for it, so I can track it's progress?
Would it be possible to move the parsing and printing into unison itself?
In the Haskell runtime you have the AST in a defined format and let unison codebase interact with it (maybe using a special effect handler?) The Haskell runtime then checks the AST if it ok and acts accordingly.
Installing a new syntax would be as simple as installing a library in unison.
@aryairani: What's the status of this in 2022? If this is still the case:
I could be wrong, but I think it will be hard to even find all of the parsing and printing code unless we are trying to plumb the record through. There are some little bits scattered around, inlined, etc.
...then I'm especially interested in this issue, as getting the parsing/pretty printing separate from everything else should be a solid code clarity win (whatever the particular incremental approach we end up taking).
I think that's still the case
I think that it's really fascinating that Unison would be so good at supporting pluggable syntax!
But at the same time I actually think that this wouldn't be worth the toll that it could take. Unison code is still going to make its way into textual tools/resources such as StackOverflow, blog posts, GitHub gists, tweets, etc. I think that it would be terribly disorienting to someone trying to learn Unison to see two similar StackOverflow answers with wildly different syntaxes.
It pains me to say it, but while this is a cool possibility, honestly I feel like it should be reserved for minor formatting adjustments (indentation/line width, etc).
But at the same time I actually think that this wouldn't be worth the toll that it could take. Unison code is still going to make its way into textual tools/resources such as StackOverflow, blog posts, GitHub gists, tweets, etc. I think that it would be terribly disorienting to someone trying to learn Unison to see two similar StackOverflow answers with wildly different syntaxes.
Being held back by legacy mediums seems a regrettable approach if one of the goals of Unison is to advance the state of the art. Why not post links/embeds in these from a source that knows how to deal with Unison?
This is, in my opinion, the missing piece from Unison at the moment.
Doing away with naming, and moving towards a structure that can describe the entirety of a system. Why tie that down to a single representation? With something like Unison, we could finally work on systems from various perspectives without any of them having to own (their little part of) it. For an example, UX designers work with tools that represent interactions that are then translated into code; often by other people. It shouldn't be inconceivable to have UX designers interface with the codebase directly, given that interactions are precisely a perspective into the system that is being built. Same goes for project management, security, etc...
At my current work, we deal with clinicians who express medical knowledge as executable rules. Having to learn a textual syntax has consistently been a bottleneck, whereas diagrammatic representations tend to come more naturally. In cases like these, too, it would make a lot of sense to cut the middle-man and embrace that the single source-of-truth of the system may have many representations. Different people are involved; interested in different things; working in different ways; accomplishing different goals. Why dictate that the system must be canonically described through a textual syntax – especially after going so far to make that unnecessary? Unison might expose a standard way of interfacing with the codebase, and leave it up to the user to build the many representations that make sense in their given contexts. (Sure, they could do that even if the interfacing happens through a textual syntax, but I think that'd be a missed opportunity.)
I don't think I'm alone with these thoughts, as even Alan Kay mentioned the work of Bret Victor on the future of user interfaces. I've personally found the talk on "The Humane Representation of Thought" particularly insightful.
Unison already requires a different way (Manager) to interact with the code base rather than just editing text, So!
Unison code is still going to make its way into textual tools/resources such as StackOverflow, blog posts, GitHub gists, tweets, etc. I think that it would be terribly disorienting to someone trying to learn Unison to see two similar StackOverflow answers with wildly different syntaxes.
While I agree here with @ceedubs - it indeed would make things harder, but wouldn't also the remediation be as easy as putting the unknown syntax into ucm and printing back as preferred syntax? Not perfect UX, but what's more important - I'm sure that the canonical syntax will be holding a major part of the market and everything else will be esoteric CoffeeScript's that only enthusiasts care about.
I think that it's really fascinating that Unison would be so good at supporting pluggable syntax!
But at the same time I actually think that this wouldn't be worth the toll that it could take. Unison code is still going to make its way into textual tools/resources such as StackOverflow, blog posts, GitHub gists, tweets, etc. I think that it would be terribly disorienting to someone trying to learn Unison to see two similar StackOverflow answers with wildly different syntaxes.
It pains me to say it, but while this is a cool possibility, honestly I feel like it should be reserved for minor formatting adjustments (indentation/line width, etc).
We could have a browser extension that translates between Uni-syntaxes
I don't see that they do this anymore, but Microsoft used to have a toggle in their web docs for switching examples between different .NET languages.
I'm considering of adding Unison as a plugin language for AnyType and I think having a more conventional syntax would be a definite advantage in that role.
@micklat That sounds cool. What does that mean?
Unison's syntax is just used for parsing and pretty-printing of definitions, but the actual definitions are stored in the codebase as their AST. This means we could support multiple syntaxes for the language. Alice could write some Unison code in Python-like syntax, add it to the codebase, and then Bob could view Alice's definition in C-like syntax or Lisp-like syntax. Your
~/.unison
file might havesyntax = Pythonish
in it to control your personal default for reading and writing.If you want to help make this happen, it would be pretty straightforward. The first step is abstracting the current parser and prettyprinter into an interface, perhaps something like:
So define this (perhaps in
Unison.Syntax
), and then provide an implementation of it for the current syntax (can put inUnison.Syntax.Default
). Then it's just an exercise in plumbing aSyntax
value everywhere that the current implementation calls the existing parser and prettyprinter directly (maybe rename or move the existing implementations to make sure that the compiler will alert you to all the places that need changing). Once that's done, the choice ofSyntax
can become a runtime parameter, chosen on startup by reading a~/.unison
file, command line flag, or something similar.