
At 11:15 AM -0500 2003/10/31, Harris, Andrew wrote:
Hi - I am trying to work out how the following function using "fix" is evaluated. I am hoping someone could look at my step-by-step breakdown of how I think evaluation works and see if I'm correct. My main question is how the order of operation (fixity?) is understood in going from step [3] to [4], if this is indeed how the evaluation would take place.
Any help is appreciated, -andrew
Here's the Haskell function:
--- fix f = f (fix f)
wierdFunc2 x y z = if y - z > z then x (y-z) z else y - z
myRemainder = fix wierdFunc2 ---
Here's my "evaluation":
You're pretty close. I've noted a couple of differences below.
myRemainder 12 5 -- [1] = fix wierdFunc2 12 5 -- [2] by substitution = wierdFunc2 fix wierdFunc2 12 5 -- [3] apply "fix"
wierdfunc2 (fix wierdFunc2) 12 5
= wierdFunc2 myRemainder 12 5 -- [4] by substitution (?)
No, equations "rewrite" only "from left to right". Skip the step above and the step below.
= myRemainder 7 5 -- [5] apply "wierdFunc2" = fix wierdFunc2 7 5 -- [6] by substitution = wierdFunc2 fix wierdFunc2 7 5 -- [7] apply "fix"
Similarly, the above needs (fix wierdFunc2) to be parenthesized.
= wierdFunc2 myRemainder 7 5 -- [8] by substitution (?)
Skip the above step.
= 2 -- [9] apply "wierdFunc2"
Dean
participants (1)
-
Dean Herington