title: F# SAFE how to deal with growth of message DU variants?
body: <p>In F# SAFE stack there is a DU type, which defines all types of messages flowing between server and client. In sample application there are &lt;10 of them, I looked on provided examples - all of them have not many possible types. But what if the application is not small - there will be hundreds of types in DU; which will become hard to maintain. So I decided to divide this type in sub-types and put logic in corresponding files.</p>
  <p>Here is my simplified type:</p>
  <pre><code> type Msg2 =
      | LoginMsg of LoginState
      | RegisterMsg of RegisterState
      | ViewUpdateMsg of ViewUpdateState
  </code></pre>
  <p>Login state is defined in another file:</p>
  <pre><code> type LoginState =
          | Login
          | LogInResult of LoginResult
  </code></pre>
  <p>Login module works with logins:</p>
  <pre><code>let workWithLogin (model: Model) (msg: LoginState) (todosApi: ITodosApi) : Model * Cmd&lt;LoginState&gt; =
      match msg with
      | LoginState.Login -&gt;
          let result =
              Cmd.OfAsync.perform todosApi.login model.InputData LoginState.LogInResult
  
          model, result
      | LoginState.LogInResult data -&gt;
          { model with
                LoginState = getVal data.Message
                Token = data.Token },
          Cmd.none
  </code></pre>
  <p>Note that it returns <code>Model * Cmd&lt;LoginState&gt;</code>.</p>
  <p>Now I need to fix my update function:</p>
  <pre><code>let update2 (msg: Msg2) (model: Model) : Model * Cmd&lt;Msg2&gt; =
       match msg with
       | LoginMsg n -&gt;
           let ret = workWithLogin model n todosApi
           model, snd ret
       | RegisterMsg n -&gt; ...
       | ViewUpdateMsg n -&gt;  ...
  </code></pre>
  <p>The problem here is that I get <code>Cmd&lt;LoginState&gt;</code> from login module and need to convert it to  <code>Cmd&lt;Msg2&gt;</code> somehow.
  <a href="https://i.stack.imgur.com/wQxqk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wQxqk.png" alt="enter image description here" /></a>
  So I either need to create new <code>Msg2</code> type or convert DU variant <code>LoginMsg of LoginState</code> to <code>Msg2</code>. I dont understand how to get <code>LogInResult</code> data from <code>Cmd&lt;LoginState&gt;</code>.</p>
  <p>How can I fix this? How the problem with many message types is solved in big projects?</p>