Implement tuples as syntax sugar for newtype for record types#556
Implement tuples as syntax sugar for newtype for record types#556andreypopp wants to merge 1 commit intopurescript:masterfrom
Conversation
Tuples are represented as
newtype TupleX a b ... = { _1 :: a, _2 :: b, ... }
This commit implements a desugaring pass which translates TupleLiteral values
and TupleBinder binders into AST corresponding to chosen representation.
|
Actually if would be more useful to represent tuples as Related question: is that possible to make type classes work for records with a closed row type? |
There's no need for that. One clean option is to use a lens for this. Unfortunately something was broken the last time I tried to use this: https://github.com/purescript-contrib/purescript-lens/blob/master/src/Control/Lens/Tuple.purs#L17-L33 |
|
I love how you were able to implement this purely as syntactic sugar for records. I wonder if it would be better to just use type synonyms, which would allow arbitrarily large tuples (record types would just be generated on the fly). We can't do type class instances even for closed rows right now. My reason is that I interpret "extensible records" to mean "labels have no fixed semantics", and attaching type class instances would violate that in my opinion. I'm open to discussion about it though. |
|
Now that #863 has been merged, I guess it's feasible to have something like this approach but with type synonyms rather than newtypes (generated on the fly, in that desugar step?) How would you feel about that? |
|
I'm not sure how I feel about it, honestly. I think records are superior to tuples in every regard apart from the lack of support for instances (even #863 won't let us define a |
|
With the |
|
Yeah, I think so. I still do occasionally wish for native tuples, but that's usually after I've been writing a lot of Haskell again ;) I can definitely live with our version. |
Discuss!
Tuples are represented as
This commit implements a desugaring pass which translates TupleLiteral values
and TupleBinder binders into AST corresponding to chosen representation.
It's OK If you are not going to merge this. Anyway, I gained more understanding of PureScript internals.