On Dec 26, 2007 5:27 AM, Ian Zimmerman itz@madbat.mine.nu wrote:
I get this:
Exception- Fail "Invalid type (not a type construction)" raised
The context: I run a toplevel built by compiling Vesa Karvonen's "extended-basis" library and doing PolyML.export (_, PolyML.rootFunction). Into this toplevel I load the enclosed Word31 module. My guess is this happens because extended-basis rebinds some basis types which are normally special-cased by the poly pretty-printer, but aren't recognized as special anymore after the rebinding. Anyway, it works ok with the normal poly.
Who's to "blame"? And is there a workaround?
I took a look at this. I would argue that this is a bug in Poly/ML, although, of course, overloading isn't a part of the Definition, so technically Poly/ML can specify it freely. The problem is around line 2732 in VALUE_OPS.ML. The problem is that the case there only accepts the FunctionType variant and does not expand type constructions. IOW, the overload code doesn't work with type abbreviations. The extended-basis library uses type abbreviations heavily. The value Word32.+ from the extended.basis lib is printed as
val it = fn : MkWordExt().Core.t BIN_OP.t
by Poly/ML. An attempt to add an overload for it gives the above mentioned error, because Poly/ML's overload code does not expand the BinOp.t type constructor to recognize it as an arrow type. You can work around this by ascribing the value explicitly with an arrow type:
RunCall.addOverload (Word32.+ : Word32.t * Word32.t -> Word32.t) "+";
(In your case, of course, you'd do the same for Word31 instead of Word32. You don't need Word31 to expose this problem.)
BTW, it didn't take a lot of time to diagnose this problem. I first reproduced the problem. Then I updated my cvs copy of Poly/ML and rebuilt it while getting a cup of coffee. Then I spent a few minutes playing in the Poly/ML REPL looking, among other things, the types of values and trying to add overloads (most of this time wasn't very productive, though). Then I grepped for the error message from Poly/ML's code and got two hits. After browsing the code for a few minutes, I realized what the problem was after following the code to see where the typeToUse value (line 2761) passed to followTypes (that raises the error) came from.
-Vesa Karvonen