swifttypescompound-type

Why Array / Dict / Optional are not compound types in Swift?


From the documentation :

In addition to user-defined named types, the Swift standard library defines many commonly used named types, including those that represent arrays, dictionaries, and optional values.

[...]

There are two compound types: function types and tuple types.

Well... It seems clear that dictionaries, arrays and optionals are named types and not compound types.

I don't understand why they are not compound types while tuple and function types are. Because from my perspective all these types are host for other types.

So two solutions :


Solution

  • The documentation clearly states that compound types are those which don't have a name. A tuple type and function types don't have names i.e when specifying these types in function signature or variable you don't say let a : Tuple or let f : function, instead you have to use their own specific notation to specify the types - let a: (Int, Int) or let f: (Int, Int) -> Int

    Compound types doesn't have anything to do with "host for other types".