Professional Documents
Culture Documents
Typesystems New
Typesystems New
Typesystems New
output
output
output
overloading
• Functions that can be applied to different types
and behave differently
• AD-HOC polymorphism
• Overloading: using same identifier for different
procedures/functions/operators in same scope
• Example: Two different functions, two distinct
types, same name.
• Polymorphic function: one function that can
process multiple types. DIFFERENT!!
overloading
cout<<y<<endl;
cout<<* xp<<endl;
cout<<*yp<<endl;
Type inference
• Type system may force user to declare all types
(C and most compiled imperative languages), or
• Language processor infers types. How?
• Each expression position provide information
(put a constraint) on type inference
1. Equality: y=x,
2. Arithmetic expressions e= a + f x
+::Num->Num ->Num THEN a::Num, f:: alpha ->
Num, e::Num
3. Function application: e=f x
e:: beta, x:: alpha , f:: alpha -> beta
4. Type constructors: f(x:r)=t
x:: a , t:: b, f:: ([a] -> b)
x :: a
func :: a ->Bool