smlpolyml

What causes the SML error: Exception- InternalError: asGenReg raised while compiling


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?


Solution

  • 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.