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

[generics-rep] Document the associativity of Product and Sum that the compiler generates #243

Open
natefaubion opened this issue Jul 30, 2018 · 1 comment
Labels
type: documentation Improvements or additions to documentation.

Comments

@natefaubion
Copy link

With instance chains you can distinguish between Product a (Product b c) and Product (Product a b) c. It would be helpful to note the ambiguity and what the compiler generates in practice.

@natefaubion natefaubion changed the title Document the associativity of Product that the compiler generates Document the associativity of Product and Sum that the compiler generates Jul 30, 2018
@hdgarrood
Copy link
Contributor

Did some research; we could add something along the lines of this to the docs:

At the moment, the compiler brackets Sums and Products right-associatively. For
example:

> data TestSum = TestA | TestB | TestC | TestD
> derive instance genericTestSum :: G.Generic TestSum _
> :t (G.to :: _ -> TestSum)
Sum (Constructor "TestA" NoArguments) (Sum (Constructor "TestB" NoArguments) (Sum (Constructor "TestC" NoArguments) (Constructor "TestD" NoArguments))) -> Test

> data TestProduct = TestProduct Int Int Int Int
> derive instance genericTestProduct :: G.Generic TestProduct _
> :t (G.to :: _ -> TestProduct)
Constructor "TestProduct" (Product (Argument Int) (Product (Argument Int) (Product (Argument Int) (Argument Int)))) -> TestProduct

Ideally, the compiler would bracket up Sums and Products so as to minimize the
depth of the resulting tree; this would help generate faster code when
constructing or pattern-matching on generic representation types. This nesting
may change in a future release, so it is recommended to avoid depending on the
way the compiler chooses to nest Sums and Products if at all possible.

@JordanMartinez JordanMartinez changed the title Document the associativity of Product and Sum that the compiler generates [generics-rep] Document the associativity of Product and Sum that the compiler generates Dec 26, 2020
@JordanMartinez JordanMartinez transferred this issue from purescript-deprecated/purescript-generics-rep Dec 26, 2020
@JordanMartinez JordanMartinez added the type: documentation Improvements or additions to documentation. label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Improvements or additions to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants