Pattern matching now possible on generic types.

Functions need to be provided to compare and retrieve elements.

Note that after preprocessing, the function to retrieve elements will not be needed once streaming.