title: Haskell defining multiple variables under one condition?
body: <p>Alright, I'm probably doing this wrong but it has got me pulling my hair out. I haven't been able to find anything to do what I want</p>
  
  <p>Take this pseudocode</p>
  
  <pre><code>my_function left right
      = another_function new_left new_right (fourth_function new_left new_right)
          where new_left = if some_condition then left else third_function left
              new_right = if some_condition then third_function right else right
  </code></pre>
  
  <p>How can I avoid rechecking some_condition? And I'm not talking about saving <code>some_condition</code> as another variable in the <code>where</code> construct. If I put <code>lets</code> inside the <code>if</code> I then duplicate the <code>in another_function new_left new_right</code>.</p>
  
  <p>In an imperative language I could do something like</p>
  
  <pre><code>int new_left;
  int new_right;
  if (condition) {
      new_left = left;
      new_right = third_function(right);
  } else {
      new_left = third_function(left);
      new_right = right;
  }
  return another_function(new_left, new_right, fourth_function(new_left, new_right));
  </code></pre>
  
  <p>I know in a functional language you're not supposed to think of doing things in a sequence, but rather as a composition of expressions, so I'm just looking for a way to write the original pseudocode such that it's DRY. And it seems like a simple and relatively common case.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Sorry for the confusion. I can't inline <code>third_function left/right</code> because I need to use it's value twice (updated pseudocode). And <code>fourth_function</code> can't be moved inside <code>another_function</code></p>