Teachers Paradise School Supplies Teacher Resources Free Encyclopedia
Teachers Paradise FREE Teaching Resources
Home Arts Crafts Audio Visual Equipment Office Supplies Teacher Resources
Main Page | Edit this page

Type inference

Type inference is a feature predominant in functional programming languages such as Haskell and ML.

Type inference automatically assigns a type signature onto a function if it is not given. In a sense, the type signature is reconstructed from the compiler/interpreter's understanding of the function's subfunctions with well defined type signatures, and thus the input/output type can be ascertained.

For example, let us consider the Haskell function length, and it is defined as:

length [] = 0
length (first:rest) = 1 + length rest

From this, it is evident that the function handles lists as inputs, and the base case of this recursive function returns an integer (Haskell "Int"). So we can reliably construct a type signature
length :: [a] -> a

Since there are no ad-hoc polymorphic subfunctions in the function definition, we can declare the function to be parametric polymorphic.



Pay for Educational Supplies & Teaching Supplies with Visa, Master Card, American Express, Discover or Paypal.
TeachersParadise.com HOME | Safe Shopping Guarantee | Help Desk
All trademarks & brands are the property of their respective owners.
Legal Notice 2000-2008 TeachersParadise.com, Inc. All Rights Reserved