1. A method for optimizing functions expressed in a declarative computer language that allows for dynamic type-checking, the method comprising the computer-implemented steps of: receiving a query that includes an invocation of a function, wherein a function declaration of the function indicates that a first set of datatypes is associated with the function; performing static type-checking on the query, wherein performing static type-checking on the query comprises performing static type-checking on the function, wherein performing static type-checking on the function comprises determining a second set of datatypes for the function, wherein the second set of datatypes includes a datatype of each argument of the function specified in the invocation; wherein the second set of datatypes is different than the first set of datatypes; and compiling the query, wherein compiling the query comprises compiling the function with the second set of datatypes; wherein the steps of the method are performed by one or more computer systems.