title: How do I Json.decode a union type?
body: <p>I have a type defined like this inside <code>module Foo exposing (..)</code>:</p>
  
  <pre><code>type Foo
      = Bar
          { a : String
          , b : String
          }
      | Baz
          ...
  </code></pre>
  
  <p>Then I've tried to create a <code>Json Decoder</code> in a separate module to decode that type like this:</p>
  
  <pre><code>barDecoder : Decoder Bar
  barDecoder =
      map2 Bar
          (field "a" string)
          (field "b" string)
  </code></pre>
  
  <p>The Elm compiler gives me an error on the <code>map2 Bar</code> line saying that type <code>Bar</code> is not found. The module that contains the decoder has <code>import Foo exposing (..)</code>. I also tried moving this function into the same module that contains the type definition and get the same error, so it doesn't have anything to do with being in a separate module.</p>
  
  <p>I've tried changing it to <code>map2 Foo.Bar</code>, but that didn't work either.</p>
  
  <p>What's the right way to decode a union type like this? </p>