JuliaLang/julia — pull request #1478 by carlobaldassi (2012-10-30 18:44:47+00:00)
Title: Add Dict comprehensions and typed Dicts -- alternative version (changes Dict literal notation)

This is an alternative version of my other pull request #1467, and it follows Stefan's proposal.

Under this framework, the rules for literal notations are more streamlined:

* using `{...}` will use the `Any` type
* using `[...]` will try to infer the type
* the `[...]` notation can be type-annontated to control the type explicitly
* if there is a `=>` symbol anywhere, it's a Dict, otherwise it's an Array
* the type annotation for Arrays is `T[...]`, for Dicts is `(K=>V)[...]`
* comprehensions are supported in all cases

Additionally, there is syntax for the empty Dict case: `{=>}`. The syntax `[=>]` is supported and gives a `Dict(None,None)` just like `[]` is a `Vector{None}`. The syntax `(K=>V)[=>]` is also supported for consistency, but it's equivalent to `(K=>V)[]`.

Apart from this, everything else works like in #1467.

Notes:

* this is a breaking change, since `{1=>2,3=>4}` is no longer a `Dict{Int,Int}` after this change.
* this change is in strong contrast to the idea of using `[...]` for Arrays and `{...}` for Dicts (as said above, it's the `=>` symbol which distinguishes them).

Personally, I strongly prefer this framework to the previous one.