title: Haskell IO Recursion (with binary tree)
body: <p>I'm new to Haskell and I'm loving it so far, but I'm struggling with some aspects of IO.
  I'm making a sort of simple &quot;Akinator&quot; application and I'm having trouble understanding how to modify a binary tree using IO recursion.
  I have my own data type:</p>
  <pre><code>data QA = P String | Q QA String QA   -- P representing person, Q representing a question
   deriving (Show, Read)
  </code></pre>
  <p>We go down the tree by answering a question with yes or no. Yes takes you to the left and no takes you to the right.
  But when I get to the end of the tree while we run the program (we reach a person), I want to be able to modify the tree by adding another QA. (We ask the user for input in case the person was not found)</p>
  <p>The function i use is:</p>
  <pre><code>play :: QA -&gt; IO QA
  </code></pre>
  <p>How do you convert the QA data type to a IO QA during the recursion and return the same QA (in IO format) but with an added Leaf/Branch?</p>
  <p>Thank you very much!</p>
  <p>-------Some of my code--------</p>
  <pre><code>play :: QA -&gt; IO QA
  play (P s) = do
     a &lt;- yesNoQuestion (&quot;Is ( &quot; ++s ++&quot; ) your person?&quot;)
     case a of
        True -&gt; do
            putStrLn &quot;I win omg so ez!&quot;
            exitSuccess -- (to exit the application without modifying
                        -- dunno if this is a good solution)
        False -&gt; do
          p &lt;- question &quot;Just curious: Who was your famous person?&quot;
          n &lt;- question &quot;Give me a question for which the answer for this person is yes&quot;
          return q -- (Here I want to return a new QA with an added question -- 
                   --and with a leaf representing a person)
  
  
  play (Q qaY s qaN) = do
      a &lt;- yesNoQuestion s
      case a of
          True -&gt; do
              pY &lt;- play qaY
              return pY -- (I want this to say (return Q pY s qaN) But this 
                        -- does not work 
            --  since all types aren't IO)
          False -&gt; do
              pN &lt;- play qaN
              return pN -- (Same as previous)
  </code></pre>