[MLton] Bug in signature ascription
Matthew Fluet
fluet at tti-c.org
Tue Feb 6 14:45:56 PST 2007
Wesley W. Terpstra wrote:
> On Feb 6, 2007, at 10:38 PM, Matthew Fluet wrote:
>> I don't believe that there is any bug in signature ascription. You
>> are simply encountering the fact that FOLD is not the principal
>> signature of Fold. If you eagerly ascribe the signature FOLD to Fold,
>> then the resulting types are too constrained to give Foldr the
>> signature FOLD. (There may be a different implementation of Foldr in
>> terms of Fold:FOLD that can ascribe Foldr the signature FOLD.)
>>
>> You can "fix" things like this:
>>
>> local
>> structure Fold = struct ... end
>> structure Foldr = struct ... end
>> in
>> structure Fold :> FOLD = Fold
>> structure Foldr :> FOLD = Foldr
>> end
>
> Let me confirm that I understand what you're saying: Foldr needs enough
> polymorphism to match the signature FOLD. Unfortunately, the
> implementation of Foldr required more polymorphism from Fold than FOLD
> let escape.
Correct.
> That's quite a nasty corner case, and I would've never
> suspected it. Thanks! I just assumed that Vesa's signature was correct
> since the whole Fold structure is deep magic that I'm terrified to
> touch. :-)
Indeed. Vesa and Stephen will have to weigh in on whether the principal
signature of Fold is useful or not.
> In fact, I've already found that Foldr.t needs five type variables, or
> it breaks variable arity polymorphism. So, I guess the wiki page which
> describes the signature is wrong. I'll correct the page as soon as I've
> found the polymorphism that Fold lost.
Again, I don' know.
> Is there any way to get a printout of the principle signature? One that
> doesn't have '???' all over it?
You can use the compiler option '-show-basis <file>', which will output
to 'file' the basis that is in scope at the end of elaboration. Just
make sure that you have an unconstrained Fold structure in scope, and
you'll be able to see what signature was inferred for it.
More information about the MLton
mailing list