title: Comparing two strings in Haskell
body: <p>I came across a rather silly practice problem that was listed as easy, so I thought I could do it.  The premise is that a doctor must hear a patient say aah in order to give a diagnosis, but the aah from the patient must match the aah requested by the doctor.  If the doctor asks for aaaaah and the patient says ah, then no diagnosis can be given.  The Haskell program is supposed to read in a doctor and a patient aah in that order and return a Bool value for if a diagnosis may be given.  At first I thought they needed to be identical so this was my code:</p>
  
  <pre><code>seeDoctor :: String -&gt; String -&gt; Bool
  seeDoctor a b = if a == b then True
                  else False
  </code></pre>
  
  <p>However, I realized I wasn't following all the rules of the problem and it wasn't so simple.  The patient may say aah for longer than the doctor and return True, so "aah" "aaaah" returns True, as does "" "aaah" and "h" "aah", but "aaah" "ah" returns False. But even if the doctor doesn't include an 'h' in their aah, the patient must, so "a" "a" returns False, but my code would return True. So if the patient says anything, it must be the necessary number of 'a's followed by a single 'h' and no other characters.  You see, once I started trying the suggested test cases, I realized how little I understood.  Can I keep a count of 'a' in each string? How do I check for extra characters? Sorry this took a while to read. Thanks for making it this far.</p>
  
  <p>Here is the exact question:</p>
  
  <blockquote>
    <p>"When we go to see a doctor, the doctor always asks us to say "aaah".
    Sometimes, the doctor needs us to say "aaaaaah", but we are only able
    to say "aaah". In that case, the doctor is unable to diagnose our
    disease, because the 'a's in our "aaah" are fewer than his or her
    requirements. Now, write a Haskell function called seeDoctor to judge
    if the doctor can diagnose us with our "aah". The input of the
    function consists of two strings. The first string is the "aaaah" the
    doctor needs and the second string is the "aah" we are able to say.
    Output "True" if our "aah" meets the requirements of the doctor, and
    output "False" otherwise. The test should pass with a "True" only when
    lowercase 'a's and 'h's are used, and each string contains a certain
    number of 'a's followed by a single 'h'."</p>
  </blockquote>