|
![]() |
||||||||||||||
Program Structure TutorialAutomatic Type InferenceProgramming language Wafl is strongly typed. However, Wafl syntax does not include type specification. All types are implicitly inferred. Usually, the program evaluation does not present definition types to user. If any type error is detected during the type checking, all inferred types are reported. In the following example there are three local function definitions. Function g is recognized to be of type (Float -> Float) (maps single float argument to float result), and function h is recognized to be of type (Integer -> Integer) (maps single integer argument to integer result). It is obvious that function f is not well defined, because first addition operand is float and second one is integer, while the addition does not allow the different operand data types. The error report contains some redundant data because all branches of the type checking process are reported to allow better understanding of reported problems. One should read the report from the bottom. Only the last block of not recognized types is valid. Each line beginning with 'OK:' suggests that the given definition type is well recognized (any possible report of problems with that definition above that line should not be considered). In our example, the type inference failed for function f and program expression. The syntax f: ('3 -> '2) suggests that f is defined as a function that maps single argument to a result, but specific types are not recognized. Source code:// This code segment intentionaly contains errors. f(7.0) where{ f(x) = g(x) + h(x); g(x) = sin(x); h(x) = x + 5; } Result:*** Loading: src Can not normalize undefined expression type: --> g(x) - f: ('2 -> '1) OK: g: (Float -> Float) OK: h: (Integer -> Integer) Type checking failed for expression: --> h(x) - f: ('2 -> '1) Type checking failed for expression: --> h(x) Subtypes are not recognized: - f: ('3 -> '2) - Program: '1 Typechecking failed! *** End loading: src
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||