<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thinking about disambiguating \case Just x -> x: There is no way that \of Just x -> ... can be correct, because Just requires an argument. Very happily, the renamer's behavior is unaffected: any variables introduced are still binding sites. So, I think we could probably detect a case like this in the type-checker and either reinterpret it correct or provide a very helpful error message.<div class=""><br class=""></div><div class="">So here's a concrete idea:</div><div class=""><br class=""></div><div class="">- Change the existing proposal to use \case instead of \of.</div><div class="">- Add a little magic to the type-checker, as specified below, to allow current usages of \case to be accepted.</div><div class="">- When the magic triggers, issue a warning (-Wdeprecated-lambda-case, on by default).</div><div class="">- Remove the magic (and its warning) in a few releases.</div><div class=""><br class=""></div><div class="">The magic:</div><div class="">- The new construct allows many patterns before the -> where the old \case allowed only one.</div><div class="">- The type-checker detects when the first of these patterns is a solitary constructor, and when this constructor is not nullary.</div><div class="">- It then reconstructs the AST to move the remaining patterns as arguments of that first one. Because our AST tracks parens manually, the new AST will even print identically to the old one.</div><div class=""><div><br class=""></div><div>This magic is, well, magical, but it's well specified, backward compatible, and unambiguous.</div><div><br class=""></div><div>What do we think?</div><div><br class=""></div><div>Richard</div><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 4, 2020, at 10:37 AM, Alejandro Serrano Mena <<a href="mailto:trupill@gmail.com" class="">trupill@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi all,</div><div class="">I agree with the sentiment. I think adding \of would be a nice way to clean up the language (in the same way that now StandaloneKindSignatures allow us to remove the weirder CUSKs), but unless we have some deprecation policy for extensions, this may confuse people more than help.</div><div class=""><br class=""></div><div class="">It's particularly bad that we cannot make this simply an extension of \case, due to the example pointed out in the thread: \case Just x -> x. Could we maybe think of some way to disambiguate those cases? I'm going to ask this in the thread too.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Alejandro<br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El vie., 4 sept. 2020 a las 0:02, Richard Eisenberg (<<a href="mailto:rae@richarde.dev" class="">rae@richarde.dev</a>>) escribió:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br class="">
<br class="">
Proposal #302 was submitted to the committee and assigned to Cale. He has made a recommendation on the GitHub trail, but I don't believe the committee has discussed this among ourselves.<br class="">
<br class="">
PR: <a href="https://github.com/ghc-proposals/ghc-proposals/pull/302" rel="noreferrer" target="_blank" class="">https://github.com/ghc-proposals/ghc-proposals/pull/302</a><br class="">
Proposal: <a href="https://github.com/JakobBruenker/ghc-proposals/blob/patch-1/proposals/0000-lambda-layout.md" rel="noreferrer" target="_blank" class="">https://github.com/JakobBruenker/ghc-proposals/blob/patch-1/proposals/0000-lambda-layout.md</a><br class="">
Cale's recommendation: <a href="https://github.com/ghc-proposals/ghc-proposals/pull/302#issuecomment-666075014" rel="noreferrer" target="_blank" class="">https://github.com/ghc-proposals/ghc-proposals/pull/302#issuecomment-666075014</a><br class="">
<br class="">
The idea, in brief, is to introduce a new syntax (guarded behind -XMultiWayLambda) \of. Here is an example, which gives you the idea:<br class="">
<br class="">
mplus :: Maybe Int -> Maybe Int -> Maybe Int<br class="">
mplus = \of<br class="">
  Nothing _ -> Nothing<br class="">
  _ Nothing -> Nothing<br class="">
  (Just x) (Just y) -> Just (x + y)<br class="">
<br class="">
The new keyword allows us to use a syntax similar to function definitions, but without repeating the name of the function. It is also like \case, but it allows multiple arguments. Guards are allowed, as usual.<br class="">
<br class="">
I really like this new syntax -- mostly because I find it very strange that we have to repeat the function name on every line. And then change the spacing when we change the function name. And I like the mnemonic "lambda of". And it allows me to write a where clause that is accessible in multiple different patterns, or an indented where clause that is usable in just one. If it didn't confuse readers, I would use this syntax all the time.<br class="">
<br class="">
Even so, I agree with Cale's recommendation to reject. We just have too much syntax! If someone were to come along and draft a concrete proposal of how we could, for example, use this syntax to replace both \case and if|, with a migration strategy, etc., then I might be in favor. Until then, I think we've spent our budget for cute, obscure bits of syntax.<br class="">
<br class="">
Richard<br class="">
_______________________________________________<br class="">
ghc-steering-committee mailing list<br class="">
<a href="mailto:ghc-steering-committee@haskell.org" target="_blank" class="">ghc-steering-committee@haskell.org</a><br class="">
<a href="https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee" rel="noreferrer" target="_blank" class="">https://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-steering-committee</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>