[swift-evolution] [pitch] Eliminate the "T1 -> T2" syntax, require "(T1) -> T2"

Haravikk swift-evolution at haravikk.me
Sat Apr 23 08:01:43 CDT 2016


While I know it might be a bit strange to have different rules for each side, I think I prefer empty brackets on the left and Void on the right, but in combination with required parenthesis on the left. So we’d have:

	() -> Void		// yes
	Void -> ()		// no
	() -> ()		// no (rhs interpreted as empty tuple which is not allowed)
	() -> Int		// yes
	Int -> Void	// no (lhs no parens)
	(Int) -> Void	// yes

I think the parenthesis helps to highlight that it’s a function/closure, I think it’s also clearer for cases like:

	((Int, String)) -> Void	// this is a closure taking a two-part tuple
	(Int, String) -> Void		// this is definitely a closure taking an Int and a String

> On 23 Apr 2016, at 11:47, Антон Жилин via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Therefore the impermissible:
> (()) -> () Is identical to:
> (Void) -> () So to follow these rules, it must instead be:
> Void -> () … and we’re back to T1 -> T2 : )
> 
> Wrong! If we enforce parentheses in function types, we won't be able to write
> Void -> ()
> Parentheses will be required on the grammar level. The correct way to write this will be:
> () -> ()  or  () -> Void
> The following will be legal:
> (Void) -> ()  and  (()) -> ()
> It is a function that takes a single parameter () and returns ().
> I additionally propose that the following should be illegal, because additional parentheses aren't needed there:
> ((())) -> ()  and  () -> (())  and just (Int) and (())
> Hope it cleared up things a little bit.
> - Anton
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160423/5d92aa74/attachment.html>


More information about the swift-evolution mailing list