Fix pattern-matching on functions.

This seems to fix the use case described in #109. /cc @michalrus