title: Haskell - simple constructor comparison (?) function
body: <p>In my project I have created a data type, that can hold one of a few types of values:</p>
  
  <pre><code>data PhpValue = VoidValue | IntValue Integer | BoolValue Bool
  </code></pre>
  
  <p>What I wanted to do now, is to have a simple way of checking if two values of the <code>PhpValue</code> type are of the same constructor (correct me if I'm confused with the terminology here, but basically what I want to check if both are, for example, are <code>IntValue</code>, without caring about the particular value). </p>
  
  <p>Here is a function I wrote for that:</p>
  
  <pre><code>sameConstructor :: PhpValue -&gt; PhpValue -&gt; Bool
  sameConstructor VoidValue VoidValue = True
  sameConstructor (IntValue _) (IntValue _) = True
  sameConstructor (BoolValue _) (BoolValue _) = True
  sameConstructor _ _ = False
  </code></pre>
  
  <p>This works as it should, but I don't really like it: if I add more constructors (like <code>FloatValue Float</code>) I am going to have to rewrite the function, and it will get bigger as my data definition gets bigger.</p>
  
  <p><strong>The Question:</strong> Is there a way of writing such a function, so that its implementation doesn't change when I add more constructors? </p>
  
  <p>For the record: I don't want to change the <code>data</code> definition, I have enough Monads in the rest of my code as it is ;) </p>