Reputation: 2239
This
- fun dist (x:real, y:real):real*real = (Math.sqrt (x*x+y*y), Math.abs(x-y));
produces an error
Error: unbound variable or constructor: abs in path Math.abs
So even with a self-made version of abs
I get
- fun abs (n : real) = if n <0.0 then ~n else n;
val abs = fn : real -> real
- fun dist (x:real, y:real) = (Math.sqrt (x*x + y*y), abs (x-y));
val dist = fn : real * real -> real * real
- dist (2.0, 3.0);
Error: Compiler bug: PPObj: ppFields in ppval.sml
I was following along in Programming in Standard ML, page 49. Not sure how to proceed.
Upvotes: 2
Views: 139
Reputation: 116
I'm guessing you've run in to this bug. I suggest you revert to an earlier version of the compiler (your program is working for me on 110.91) and try again.
Upvotes: 2
Reputation: 16105
Edit: I responded with saying that the library function is called Real.abs
and not Math.abs
and remarked that it handles several corner cases (±infinity, ±0.0, ±NaN) that your custom abs
function does not.
If, however, you would like to try and make your own abs
function work, I've tried to run your program in SML/NJ 110.79 (apt install smlnj
), Poly/ML 5.7.1 (apt install polyml
) and Moscow ML 2.10 (http://try.mosml.org) without getting the bug. Perhaps you're running a flakey version, or you're experiencing 64-bit issues?
Upvotes: 0