# Help with where 0.6 syntax

**URL:** <https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 19, 2017, 1:21pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971 "2017-09-19T13:21:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 1:21pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/1 "2017-09-19T13:21:44Z")

</div>

My Julia 0.5 code looks like this. What is the 0.6 syntax?

```julia
using StaticArrays
immutable Point3 <: FieldVector{Float64}
    x::Float64
    y::Float64
    z::Float64
end

```

Thank you very much for any hint.  
Petr

edit:  
the problem was the missing dimension. The implicit constructor still works

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [September 19, 2017, 1:45pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/2 "2017-09-19T13:45:23Z")

</div>

The code you wrote would be the same. The difference comes in the constructors. Even then you only need to use it for parametric types (should `Point3` be `Point3{T}`?).

You would use `where` in the following example

(fixed as per @tamasgal’s suggestion below so as not to cause confusion)

```julia
immutable Point3{T} <: FieldVector{3, T<:AbstractFloat}
    x::T 
    y::T
    z::T 
    Point3{T}() where T = Point3{T}(rand(T), rand(T), rand(T))
end

```

In this example you don’t need `where T<:AbstractFloat` because this constraint already appears in the type definition. You are free to declare these types of constructors both inside and outside of `immutable`. You can also create `Point3(...)` constructors that don’t take type parameters (the parameter will be determined by the function’s return type).

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [September 19, 2017, 1:48pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/3 "2017-09-19T13:48:51Z")

</div>

And btw. you should define the dimension like `FieldVector{3, T<:AbstractFloat}`, otherwise it’s an invalid subtype.

Just a slightly modified answer from ExpandingMan:

```julia
struct Point3{T} <: FieldVector{3, T<:AbstractFloat}
    x::T 
    y::T
    z::T 
    Point3{T}() where T = Point3{T}(rand(), rand(), rand())
end

```

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 2:07pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/4 "2017-09-19T14:07:58Z")

</div>

Thank you a lot for the answers.  
Actually, as @tamasgal pointed out, the problem was with the specification of the dimension.  
So, the code

```julia
using StaticArrays
immutable Point3 <: FieldVector{3,Float64}
    x::Float64
    y::Float64
    z::Float64
end
a = Point3(1, 1,1)
3-element Point3:
 1.0
 1.0
 1.0

```

works without definition of the constructor - there is still the implicit constructor available. So, actually, the problem was not related to the 0.6 syntax but to the interface change in the StaticArrays.  
Thank you both for the hints.

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 2:27pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/5 "2017-09-19T14:27:37Z")

</div>

Another similar story. Is it possible to create an abstract type of following properties?  
Again, old 0.5 era code

```julia
using StaticArrays

abstract FEM_Struct <: FieldVector{UInt32}

immutable Edge <: FEM_Struct
    v1::UInt32
    v2::UInt32
end

immutable Triangle <: FEM_Struct
    v1::UInt32
    v2::UInt32
    v3::UInt32
end

immutable Quadrilateral <: FEM_Struct
    v1::UInt32
    v2::UInt32
    v3::UInt32
    v4::UInt32
end
etc... up to hexahedron

```

Again, the same problem with the interface StaticArray dimension.

```julia
julia> abstract CST_Struct <: FieldVector{UInt32}

WARNING: deprecated syntax "abstract CST_Struct<:FieldVector{UInt32}" at REPL[21]:1.
Use "abstract type CST_Struct<:FieldVector{UInt32} end" instead.
ERROR: invalid subtyping in definition of CST_Struct

```

How can I propagate the dimension N into the abstract and concrete type information?

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 2:46pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/6 "2017-09-19T14:46:07Z")

</div>

So, after some permutation of keywords, the simple solution is:

```julia
julia> abstract type FEM_Struct{N} <: FieldVector{N,UInt32} end
julia> immutable Edge <: FEM_Struct{2}
           v1::UInt32
           v2::UInt32
       end

julia> a = Edge(1,1)
2-element Edge:
 0x00000001
 0x00000001

```

Still, the type system with abstract hierarchy seems little bit magical to me, and even more magical with the 0.6 syntax.  
Is there a blog post that would explain this for “spaghetti coders” like myself?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 19, 2017, 3:41pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/7 "2017-09-19T15:41:10Z")

</div>

> [@phlavenk](#):
>
> Is there a blog post that would explain this for “spaghetti coders” like myself?

Have you read the relevant parts of the manual? I found them pretty clear, they are full of examples.

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 5:34pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/8 "2017-09-19T17:34:40Z")

</div>

I’ve just read that section of the manual, and finally found the small missing piece of information well hidden for quick reading (for me unfortunately up till now)

If I understand it right, there are actually 2 completely different uses of types mixed together in the manual chapter.

1. A type representing some data. Can be concrete or parametric, this doesn’t matter. I use it as a template to store my data somewhere in the memory.
2. A type definition used only for dispatch (flow of types). Never carrying data, just representing a pattern which some real object may or may not match. And this is the only case in which the `where` clause is used to restrict/specify the set of different kinds of objects.

Is my view correct, or am I missing something more fundamental.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 19, 2017, 5:44pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/9 "2017-09-19T17:44:34Z")

</div>

I think you missed quite a bit.

1. _concrete_ and _parametric_ are orthogonal concepts. A type can be abstract/concrete, with or without parameters, all four combinations are valid.

2. types and their parameters can be used for dispatch. Values cannot (unless you convert them to types, see `Val`). Whether the type has fields is not relevant for dispatch _per se_ in this sense.

I reread the manual from time to time. It changes quite a bit (kind people invest a lot of time in improving it, actually), and even parts that don’t change much reveal multiple layers. Not unlike a good piece of literature.

Also, it pays not to be very teleological. Instead assigning each concept a single purpose, think of the language as a big box of building blocks, which you can use to create programs. Accidental features and applications emerge all the time, some end up in the manual, some get better compiler support, etc.

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [September 19, 2017, 6:07pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/10 "2017-09-19T18:07:17Z")

</div>

I see. This needs some digestion and I copy your view on not diving into theology. Even with my limited knowledge of the type system I’m very happy with how Julia language and the ecosystem serves me to be productive. The same with C++ where I use only the parts I’m familiar with and that’s OK.

Regarding the manual - I thing the manual is very well written. What I’m missing is a jupyter notebook with more hard-core examples on the given topics. Definitely, at least the UnionAll concept may deserves such approach.

I’d like to thank you all for your time and thank for the help - with the hints I’ve now managed to migrate my code to 0.6 syntax.

Petr

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 19, 2017, 7:27pm UTC](https://discourse.julialang.org/t/help-with-where-0-6-syntax/5971/11 "2017-09-19T19:27:53Z")

</div>

> [@phlavenk](#):
>
> What I’m missing is a jupyter notebook with more hard-core examples on the given topics.

Then check out

> **[GitHub - mitmath/18S096: 18.S096 three-week course at MIT](https://github.com/mitmath/18S096)**
>
> 18.S096 three-week course at MIT. Contribute to mitmath/18S096 development by creating an account on GitHub.

It is treasure chest of real eye-openers. Many gave me food for thought for days.

BTW, I wrote _tele_ology, ie the looking at the language constructs from the perspective of a construed purpose.
