0

I am learning SML, and couldn't figure out why the following textbook code generates an error:

fun  recip (x,y) = let val t = x *x + y *y in (x /t, ~y/t) end;

The error is:

Exception- InternalError: asGenReg raised while compiling

This is with Poly/ML 5.7.1.

The code computes the reciprocal of a complex number (x,y). I tried adding ; and parentheses at places to no avail.

Strangely, the following changed (incorrect) definition works without any error.

fun  recip (x,y) = let val t = x *x + y *y in (x, ~y/t) end; 

The error message is not very informational.

Can someone help explain where the error is and how to fix it?

thor
  • 21,418
  • 31
  • 87
  • 173
  • 1
    This compiles fine with MLton 20180207. So this looks like a polyml bug. – qouify Jan 01 '22 at 15:52
  • 1
    "Internal" errors are bugs in the language implementation; there is pretty much nothing you can do about it. Try updating polyml (it's at 5.9 now). If that still doesn't work, consider posting an issue on their github. – molbdnilo Jan 02 '22 at 09:27

1 Answers1

1

As the comments @qouify and @mobdnilo pointed out, this error seems to be a bug of the particular version of PolyML in Ubuntu. I reinstalled the PolyML by compiling from source to the latest version (5.9), and the error is gone.

thor
  • 21,418
  • 31
  • 87
  • 173