[mercury-users] literature polymorphic recursive calls

Ian MacLarty maclarty at cs.mu.OZ.AU
Thu Jun 23 12:25:48 AEST 2005


On 23 Jun 2005, at 10:01, Peter Stuckey wrote:

>
> On 22/06/2005, at 4:37 PM, Ralph Becket wrote:
>
>> Tom Schrijvers, Wednesday, 22 June 2005:
>>>
>>>  I guess Mercury takes a third
>>> approach: it does multiple iterations to handle some non-problematic
>>> recursive definitions. What happens if the limit is reached? I 
>>> should try
>>> it :)
>>
>> Well, even HM checkers can take an exponential amount of time in the
>> worst case!  In practice this problem just doesn't arise (at least, 
>> not
>> in my experience).
>
> In fact because of adhoc overladoing it is worse for Mercury.
> But in practice problems dont arise.
>
> Still in my opinion Mercury should just use the HM assumption if
> there are no declarations. In any polymorphic recusrive code the
> iterated approach will never infer the polymorphic type
>
> p(X,Y) :- (X == Y -> p(true,false) ; p(1,2))
>

I don't know very much about the type inference problem being discussed 
in this thread, but the Mercury compiler infers the types of the above 
just fine (well a slightly modified version of the above, since the 
above isn't correct Mercury syntax).


:- module peter.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module bool, int, float.

main(!IO) :-
         ( if p(1.0, 2.0) then
                 io.write_string("yes", !IO)
         else
                 io.write_string("no", !IO)
         ),
         nl(!IO).

% :- pred p(X::in, X::in) is semidet.
:- mode p(in, in) is semidet.

p(X, Y) :- (X = Y -> p(yes, no) ; p(1, 2)).


$ mmc peter --infer-all
peter.m:022: Inferred :- pred p(T2, T2).


Ian.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list