pattern matching in function