title: Patterns for managing/representing selection from a set of options in Haskell
body: <p>Algebraic data types make it easy to allow one item from a set to be selected: just use an appropriate sum type.</p>
  <p>I'm curious how one would implement the option of selecting strictly n items or fewer from a set. I can see how it might be possible to implement this with Data.Set, but I wonder if there's a pattern or an algebraic structure that would be more robust.</p>
  <p>Say a burger can have three toppings from the set Pickle | Onion | Lettuce | Tomato etc. It's reasonable to want to display all the options in a UI, so if we use Data.Set, right away I notice that Data.Set.all is missing, so there's no easy way to print all the values that can be selected. But Data.Set.powerSet is available, so I'm thinking maybe I should be getting the user to choose an element of the subset of the power set with cardinality &lt;= 3.</p>
  <p>Using an element of the power set to represent a selection from the base set seems like a good idea. It doesn't look much like any UI I can think of, though. The power set functor is a monad, though I'm not sure if this is relevant (See discussion about power set as a functor here <a href="https://stackoverflow.com/questions/19177125/sets-functors-and-eq-confusion">Sets, Functors and Eq confusion</a>).</p>
  <p>Maybe someone who has solved a similar problem before will have advice on how to best make this work. I'm really looking for conceptual insights into what an &quot;n choose k&quot; type looks like, if that makes sense.</p>