title: Algorithm for matching object properties with rules
body: <p>Apologies for the unclear title. Here's the explanation:</p>
  
  <p>I have a type of object Foo having properties a,b,c,d. Lets say each of these properties(type of string/bool) can have individually 3 unique value (a has 1,2,3; b has 11,12,13 and so on).</p>
  
  <p>I have a set of rules against which I want to match the list of Foo objects. The rules can have one or more property with a value selected. Example:
  rule 1 : a=1
  rule 2 : b=12 and a=2</p>
  
  <p>I wanted to know what would be the optimum way for getting the rules matched (C#/Haskell based solution would be preferable though just an explanation of algorithm is also fine).</p>
  
  <p>I mention C# as I would be interested if there is any possible way we can use LINQ for these kind of matching. Haskell is mentioned as a proxy for functional language , so a recursive, branch free approach.</p>
  
  <p>I am currently using a dictionary to build rules and then using reflections to get the match complete. The best thing I like about the current solution is that if we need to add a new property then its easy, plus due to less branching the code is quite easy and small to understand.</p>
  
  <p><strong>Adding an example for greater clarity</strong></p>
  
  <p>We have a list of animal objects with following properties</p>
  
  <pre><code>Object:Animal
  Properties: Color, LivingEnvironment, Place, Mammal (all properties are of type string)
  </code></pre>
  
  <p><strong>Data:</strong></p>
  
  <pre><code>Animal1 : Red, Water, Arctic, No
  Animal2 : Black, Land, Asia, No
  Animal3 : Blue, Land, UK, Yes
  </code></pre>
  
  <p><strong>Rule</strong></p>
  
  <pre><code>Rule1 : Color=Red And LivingEnvironment=Land
  Rule2 : Color=Red And LivingEnvironment=Water
  Rule3 : COlor=Blue And Place=UK And Mammal=Yes
  </code></pre>
  
  <p>The rules are configurable from the user interface, so they are not known at the compile time.
  Potentially a user can come along and change Rule 3 to a new definition</p>
  
  <pre><code>Rule3 : Color=Blue And PLace=UK
  </code></pre>
  
  <p>I hope this clarifies some of the confusion that has been caused earlier.</p>