<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-09-07 21:21 GMT+01:00 Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
Am Montag, den 07.09.2015, 19:25 +0000 schrieb Simon Peyton Jones:<br>
> > Are we okay with stealing some operator sections for this? E.G. (x<br>
> > > > ). I think the boxed sums larger than 2 choices are all technically overlapping with sections.<br>
><br>
> I hadn't thought of that. I suppose that in distfix notation we<br>
> could require spaces<br>
> (x | |)<br>
> since vertical bar by itself isn't an operator. But then (_||) x<br>
> might feel more compact.<br>
><br>
> Also a section (x ||) isn't valid in a pattern, so we would not need<br>
> to require spaces there.<br>
><br>
> But my gut feel is: yes, with AnonymousSums we should just steal the<br>
> syntax. It won't hurt existing code (since it won't use<br>
> AnonymousSums), and if you *are* using AnonymousSums then the distfix<br>
> notation is probably more valuable than the sections for an operator<br>
> you probably aren't using.<br>
<br>
I wonder if this syntax for constructors is really that great. Yes, you<br>
there is similarly with the type constructor (which is nice), but for<br>
the data constructor, do we really want an unary encoding and have our<br>
users count bars?<br>
<br>
I believe the user (and also us, having to read core) would be better<br>
served by some syntax that involves plain numbers.<br></blockquote><div><br></div><div>I reacted the same way to the proposed syntax.</div><div>Imagine already having an anonymous sum type and then deciding adding another constructor. Naturally you'd have to update your code to handle the new constructor, but you also need to update the code for all other constructors as well by adding another bar in the right place. That seems unnecessary and there's no need to do that for named sum types.</div><div><br></div><div>What about explicitly stating the index as a number?</div><div><br></div><div><div>(1 | Int) :: ( String | Int | Bool )</div></div><div><div>(#1 | Int #) :: (# String | Int | Bool #)</div></div><div><br></div><div>case sum of</div><div> (0 | myString ) -> ...</div><div> (1 | myInt ) -> ...</div><div> (2 | myBool ) -> ...</div><div><br></div><div>This allows you to at least add new constructors at the end without changing existing code.</div><div>Is it harder to resolve by type inference since we're not stating the number of constructors? If so we could do something similar to Joachim's proposal;</div><div><br></div><div>case sum of</div><div><div> (0 of 3 | myString ) -> ...</div><div> (1 of 3 | myInt ) -> ...</div><div> (2 of 3 | myBool ) -> ...</div></div><div><br></div><div>.. and at least you don't have to count bars.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Given that of is already a keyword, how about something involving "3<br>
of 4"? For example<br>
<br>
(Put# True in 3 of 5) :: (# a | b | Bool | d | e #)<br>
<br>
and<br>
<br>
case sum of<br>
(Put# x in 1 of 3) -> ...<br>
(Put# x in 2 of 3) -> ...<br>
(Put# x in 3 of 3) -> ...<br>
<br>
(If "as" were a keyword, (Put# x as 2 of 3) would sound even better.)<br>
<br>
<br>
I don’t find this particular choice very great, but something with<br>
numbers rather than ASCII art seems to make more sense here. Is there<br>
something even better?<br>
<br>
Greetings,<br>
Joachim<br>
<span class=""><font color="#888888"><br>
<br>
<br>
<br>
--<br>
Joachim “nomeata” Breitner<br>
<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="http://www.joachim-breitner.de/" rel="noreferrer" target="_blank">http://www.joachim-breitner.de/</a><br>
Jabber: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a> • GPG-Key: 0xF0FBF51F<br>
Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
</font></span><br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div></div>