Wednesday, January 28, 2009

Ch3, Ex1

Its wrong because there is no implicit type casting(that implicitly converts a float to int) in oz and given program will only work for integers. Correct Abs should check whether the input is an int or float and then do the appropriate check.

fun {Abs X}
case { X} of
true andthen X<0 then ~X
[]true then X
[]false andthen X<0.0 then ~X
[]false then X

No comments:

Post a Comment