Syntactic sugar for destructuring patterns in more places #280
Replies: 6 comments 7 replies
-
To explicate my position in this more formal non-Discord context: I am in favor of proposal 2 or 3. I have no particular opinion about whether the primitive operators should handle this and be desugared by the compiler, or whether the public interfaces should be macros which expand into primitive operators. From a user's perspective, I don't believe it matters. (Coalton should be able to print the pre-macro-expansion source form in its error messages, but that's a separate discussion.) I also very much want I'm opposed to proposal 1 because:
|
Beta Was this translation helpful? Give feedback.
-
I'm in favor of proposal 2. Code desugared in macros isn't visible to the compiler, and leads to worse error messages. |
Beta Was this translation helpful? Give feedback.
-
I like proposal 2 or 3. I think pattern matching is such a core part of ADT systems that having the function definitions themselves be able to match seems intuitive from a UX perspective. I don't think I would need a let binding to be able to match, but come to think of it, it would be nice to capture a whole match. If I recall correctly, In haskell this would be |
Beta Was this translation helpful? Give feedback.
-
When using optima in other settings, I have defined LMATCH as the obvious composition of LAMBDA and MATCH. Seems to work well for me, which is one vote for proposal 1. |
Beta Was this translation helpful? Give feedback.
-
I've found myself writing package-local macros to try and simplify
Which may reflect my lack of CL and Coalton knowledge more than anything. |
Beta Was this translation helpful? Give feedback.
-
I was entranced by the cleaness of haskell syntax/language, and inspired to make a defun macro that transform a haskell-like function definition into nested match of a single variable:
Posting this I would like to know also if |
Beta Was this translation helpful? Give feedback.
-
So, you probably have written this a million times by now:
Or perhaps even
There's been desire and enthusiasm to make cases like these easier to type, since they come up frequently. This discussion thread is to collect proposals and discuss them. If you have a new proposal, please add a
## Proposal n: title
and discuss what it is. If you're commenting on a proposal, please mention it by number.To start, here are some proposals.
Proposal 0: Unproposal
One proposal is to do nothing. The language is simpler with fewer, more orthogonal syntactic constructs. Writing a formal semantics for Coalton wouldn't require having the user make simplifying assumptions (even if they're "without loss of generality"). Code processing Coalton is simpler. Code producing Coalton is simpler. Writing debuggers (and related functionality) is slightly simpler.
The negative is that we don't actually address this pain point.
Proposal 1: Sugar macros
We could add some new macros to Coalton. Coalton would remain as-is, but the new macros would be available for people who want them. For instance, we could have
define*
andfn*
for destructuring variants (think*
as "splat").This could be generalized to multiple arguments. The macro's pseudocode would be something like
Pros: Orthogonality and a small language are maintained, "just library code"
Cons: Now users have a choice between
define
anddefine*
. If everybody ends up writingdefine*
anyway, what's the point?Proposoal 2: Build sugar into
define
andfn
We could also extend the AST to support this directly. The compiler internally would perform the rewrite into simpler base operators.
Pros: Fewer operators, more homogeneous code, probably nicer debugging in theory
Cons: The "small set of operators" are now syntactically overloaded with many ways to write them
Proposal 3: Make
%define
and%fn
core operators, letdefine
andfn
be sugarThis is proposal 1, but with a different naming convention. We could define
define
andfn
as sugar operators in the library and let%define
(or some other name) be the "core" variants.Pros: Small language in tact and sort of "hidden", formal semantics still easy to write, clear delineation of what's "internal" (though accessible!) to users
Cons: The "core" language is no longer idiomatic.
It's probably worth noting Haskell goes through a severe desugaring phase, and that's worked well for them AFAIK.
Beta Was this translation helpful? Give feedback.
All reactions