finite types and polymorphic functions

proposed fixes for #294 and #297.