Hacker News new | comments | ask | show | jobs | submit login

What was the design decision that required function declaration to be :

func hello(name: String) -> String { }

rather than,

func hello(name: String) : String { }

It seems pretty consistent with functions in a set-notation sense, with functions that map a tuple of stuff to something else. The mapping being indicated by an arrow instead of a colon.

The functional mapping also makes sense. Thanks for the pointer.

I was thinking more about Types here

var name : String

func nameMe(name: String) : String

I was half-thinking the same, but types and sets feel interchangeable on an intuitive level in such cases.

Having both `: String` and `: String` seems to suggest that they are the same type, which they are not. `nameMe(_)` is a function type, while `name` is a "plain value", so to speak. I think that using arrows more clearly indicates that it's a mapping from something to something else -- in the case of Swift, I guess a mapping from a tuple to something else.

And think about anonymous functions, in general since I haven't looked into Swift anonymous functions. If you indicate a function like this:

`func nameMe(name: String) : String`

How are you supposed to indicate an anonymous function? Like this:

`(name: String) : String`

Then it seems to say that name is a type of String, which in turn is a type of String. I guess you could add something like a lambda to distinguish it:

`(λ name => name): String`

But now you've still effectively said that both `name` (a value of type string) is the same type as the anonymous function (a function with one argument). That's clearly wrong.

Using arrows for functions seems to be better when you start to want to talk about types and values by themselves, like:

`1: Int`, `"hello": String`, `(λx => x) : a -> a`

Point well received.


Fat arrow looks more appealing than simple arrow.

All the other pieces look very well designed.

The single-line arrow has both precedent in set theory, type theory, and mathematical logic.

Rust is using similar declaration: fn hello(name: str) -> str { }

You might find this handy: http://fuckingswiftblocksyntax.com/

Thanks for the link.

I think, the function type :

(Int, Int) -> Int

may have been the main reason, but having

(Int, Int) : Int

func nameMe(name: String, calName: ((Int, Int) : Int))

would still have worked, and made the syntax more aesthetic.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact