title: How to correctly define and use global variables in the module in Julia?
body: <p>In Fortran, we know that we can in a module define a global variable (use the private property), so that we can use the subroutines in the module to set or change the values of that variable. See below,</p>
  <pre><code>module Mod
  integer, parameter :: r8=selected_real_kind(15,9)
  real(kind=r8), private, save :: var
  contains
  subroutine f(x)
  real(kind=r8) :: x
  var = 2.0_r8*x
  end subroutine f
  end
  </code></pre>
  <p>As we can see, we can call f(x) and set the var in the module to be 2x.</p>
  <p>Now in Julia, it seems like below,</p>
  <pre><code>module Mod
  global var
  function f(x::Float64)
  global var = 2.0*x
  return nothing
  end
  </code></pre>
  <ol>
  <li><p>I mean, in the function, if var is on the left hand side, do I have to specify the key word 'global' every time?</p>
  </li>
  <li><p>I also tried to give the global var a type, like</p>
  <p>global var::Float64</p>
  </li>
  </ol>
  <p>But it gives me an error</p>
  <pre><code>syntax: type declarations on global variables are not yet supported
  </code></pre>
  <p>It seems i can only do either just specify nothing, like just</p>
  <pre><code>global var
  </code></pre>
  <p>or give it a value while setting its type,</p>
  <pre><code>global var=0.0::Float64
  </code></pre>
  <p>Is there better to just give the global var a type before using it?</p>