[MLton] Bug in signature ascription

Matthew Fluet fluet at tti-c.org
Tue Feb 6 13:38:12 PST 2007



Wesley W. Terpstra wrote:
> Attached are fold.sig and fold.sml. I am using a svn mlton from Jan 7th.
> 
> When compiling, you'll get the following error:
>> Error: fold.sml 16.19.
>>   Variable type in structure disagrees with signature.
>>     variable: step0
>>     structure: _ -> ((_ * [??? -> ???]) -> (((_ * [??? -> ???]) -> _) 
>> -> _))
>>     signature: _ -> ((_ * ['a]) -> (((_ * ['a]) -> _) -> _))
>> Error: fold.sml 16.19.
>>   Variable type in structure disagrees with signature.
>>     variable: step1
>>     structure: _
>>                -> ((_ * [??? -> ???]) -> (_ -> (((_ * [??? -> ???]) -> 
>> _) -> _)))
>>     signature: _ -> ((_ * ['a]) -> (_ -> (((_ * ['a]) -> _) -> _)))
>> compilation aborted: parseAndElaborate reported errors
> 
> However, when the signature ascription from EITHER Fold or Foldr is 
> removed, it compiles.
> The error only appears when the signature is bound to both structures at 
> the same time.
> Even if the error is correct, I should have gotten it with just binding 
> Foldr.

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




More information about the MLton mailing list