[mercury-users] unresolved polymorphism in read_term_from_string

Jeff Thompson jeff at thefirst.org
Mon Feb 13 04:54:24 AEDT 2012


On 2/11/2012 9:52 PM, Julien Fischer wrote:
>
> Hi,
>
> On Sat, 11 Feb 2012, Jeff Thompson wrote:
>
>> Hello again.  I've been working with the code parser, and gratified 
>> that it does what I expect.  The code below correctly outputs 
>> "test".  However, the predicate is declared as
>> :- pred read_term_from_string(string::in, string::in, posn::out, 
>> read_term(T)::out) is det.
>>
>> and the compiler outputs the warning:
>> test.m:004: In predicate `main'/2:
>> test.m:004:   warning: unresolved polymorphism.
>> test.m:004:   The variables with unbound types were:
>> test.m:004:     V_14: term.term(T)
>> test.m:004:     V_8: list.list(term.term(T))
>> test.m:004:     V_6: varset.varset(T)
>> test.m:004:     Term: term_io.read_term(T)
>> test.m:004:   The unbound type variables will be implicitly bound to the
>> test.m:004:   builtin type `void'.
>>
>> Do I need to bind the type T to `void' when calling 
>> read_term_from_string? If so, how?
>
> You can't, the compiler is telling you that that is what *it* is doing in
> this case.  It is doing that because it cannot infer a binding for the
> type variable T.  There are two things you can do about this:
>
> (1) ignore the issue by invoking mmc with the
>     --no-warn-unresolved-polymorphism option.
>
> (2) Provide some extra type information that allows the compiler to
> infer a binding for T.
>
> In a bit more detail:
>
> The problem arises becuase the type of the 4th argument (Term) of the 
> goal
>
>    read_term_from_string("", "test.", _Posn, Term)
>
> is read_term(T).  There is nothing else in the remainder of this program
> that provides a binding for T.
>
> Solution (2) involves using the with_type operation, ':', to annotate
> the 4th argument of read_term_from_string with enough type information
> to allow the binding for T to be determined, for example,
>
>    read_term_from_string("", "test.", _Posn, Term : read_term(generic))
>
> (generic/0 is defined in the term module.)

Thank you for the detailed response.  I suspected there was a way to 
provide the type information but couldn't find it in the language ref or 
examples.  That fixed it.

Thanks again,
- Jeff

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list