# Short type declarations (syntax sugar)?

**URL:** <https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114>\
**Category:** Internals & Design\
**Tags:** proposal, suggestions, syntax\
**Created:** [July 7, 2019, 1:07pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114 "2019-07-07T13:07:13Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [July 8, 2019, 4:11pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/21 "2019-07-08T16:11:05Z")

</div>

Sure is `Tuple{1, :foo}` valid (but uninhabited).

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [July 8, 2019, 4:11pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/22 "2019-07-08T16:11:25Z")

</div>

> [@jeff.bezanson](#):
>
> Maybe in the future we’ll have named type parameters instead of just positional type parameters, which could be quite interesting, and would be a better use of the syntax.

Yes, that had occurred to me and would clash badly with this syntax idea. It makes much more sense to me for the parameter names of parametric types to be significant by default than for argument names of functions to be significant by default. Writing `Array{N=1}` for `Vector` and `Array{N=3}` for a three-tensor could be handy and general.

In the other direction, supporting more direct syntax for e.g. [Units](https://github.com/PainterQubits/Unitful.jl/blob/master/src/types.jl) may be worth considering, although they’ve used non-standard string literals to address this already.

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [July 8, 2019, 4:13pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/23 "2019-07-08T16:13:00Z")

</div>

The other issue is that `ccall` doesn’t really make sense for arbitrary julia tuple types, and needs to have the types written out in the call — it can’t accept an arbitrary tuple-type-valued expression (e.g. `ccall(:foo, RT, ArgT, ...)`). Reflection functions that take tuple types do though. Given that, there’s no reason to impose the extra syntactic overhead of `Tuple{ }` in ccall.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [July 8, 2019, 4:15pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/24 "2019-07-08T16:15:46Z")

</div>

> [@jeff.bezanson](#):
>
> The other issue is that `ccall` doesn’t really make sense for arbitrary julia tuple types, and needs to have the types written out in the call

But the same applies to named tuples and `llvmcall`, right?

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [July 8, 2019, 4:21pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/25 "2019-07-08T16:21:45Z")

</div>

`llvmcall` I’m not sure about; it could probably use tuples of types as well.

With NamedTuples we also have e.g. `NamedTuple{n, T} where T<:Tuple{Any,Any}`, the type of 2-element NamedTuples. Basically, we can reuse existing capabilities of the type system. If the second parameter had to be a tuple of types, supporting that alternate representation would leak everywhere in the type system. By next year we’d be debating whether `(Int,) == Tuple{Int}` 🙂

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [July 8, 2019, 5:57pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/26 "2019-07-08T17:57:17Z")

</div>

Yes, a macro is the best option I can see here so far. E.g. `@NT(a::Int, b::String)`.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [July 9, 2019, 12:22pm UTC](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114/27 "2019-07-09T12:22:14Z")

</div>

Handy constructors are also defined in [NamedTupleTools](https://github.com/JeffreySarnoff/NamedTupleTools.jl)

[Previous page](https://discourse.julialang.org/t/short-type-declarations-syntax-sugar/26114.md?page=1)
