[mercury-users] Type inference

Jakob Puchinger jakobp at csse.unimelb.edu.au
Tue Jan 15 11:47:48 AEDT 2008


Hi,

I have a strange problem with type inference, the following predicate:

create_empty_colgen_dw_solver(ColgenSolver, MasterSolver, ArtMult) :-
    semipure get_solver_id(SID),
    impure set_solver_id(SID+1),
    impure SPSolvers = ref.new(array([])),
    impure Sense = ref.new(minimise),
    impure VarId = ref.new(0),
    impure VarKJMap = ref.new(map.init),
    impure ArtVars = ref.new([]),
    impure S = ref.new(0),
    impure N0 = ref.new(0),
    impure N = ref.new(array([])),
    impure K = ref.new(array([])),
    impure A = ref.new(array([])),
    impure AR = ref.new(array([])),
    impure OV0 = ref.new(array([])),
    impure C0 = ref.new(array([])),
    impure C = ref.new(array([])),
    impure D = ref.new(map.init),
    impure DR = ref.new(map.init),
    impure Sol = ref.new(array([])),
    impure CM = ref.new(map.init),
    impure RCM = ref.new(map.init),
    impure ConvRows = ref.new(map.init),
    impure ActiveSP = ref.new(map.init),
    impure Status = ref.new(is_not_solved),
    ColgenSolver = 'new colgen_dw_solver'(SID, MasterSolver, ArtMult, Status,
        SPSolvers, Sense, VarId, VarKJMap, ArtVars, S, N0, N, K, A, AR, OV0,
        C0, C, D, DR, CM, RCM, ConvRows, ActiveSP, Sol).

gives the following error message:
colgen_dw_new.m:894: In clause for predicate `create_empty_colgen_dw_solver'/3:
colgen_dw_new.m:894:   warning: highly ambiguous overloading.
colgen_dw_new.m:894:   This may cause type-checking to be very slow. It may
colgen_dw_new.m:894:   also make your code difficult to understand.
colgen_dw_new.m:894:   The following symbols were overloaded in the following
colgen_dw_new.m:894:   contexts.
colgen_dw_new.m:859:   The predicate symbol predicate `=<'/2.
colgen_dw_new.m:859:   The possible matches are:
colgen_dw_new.m:859:     predicate `int.=<'/2,
colgen_dw_new.m:859:     predicate `float.=<'/2.
colgen_dw_new.m:868:   The function symbol `+'/2.
colgen_dw_new.m:868:   The possible matches are:
colgen_dw_new.m:868:     function `float.+'/2,
colgen_dw_new.m:868:     function `int.+'/2.
colgen_dw_new.m:877:   The function symbol `map.init'/0.
colgen_dw_new.m:877:   The possible matches are:
colgen_dw_new.m:877:     predicate `map.init'/1,
colgen_dw_new.m:877:     function `map.init'/0.
colgen_dw_new.m:888:   The function symbol `map.init'/0 is also overloaded
colgen_dw_new.m:888:   here.
colgen_dw_new.m:889:   The function symbol `map.init'/0 is also overloaded
colgen_dw_new.m:889:   here.
colgen_dw_new.m:891:   The function symbol `map.init'/0 is also overloaded
colgen_dw_new.m:891:   here.
colgen_dw_new.m:892:   The function symbol `map.init'/0 is also overloaded
colgen_dw_new.m:892:   here.
colgen_dw_new.m:894:   The function symbol `map.init'/0 is also overloaded
colgen_dw_new.m:894:   here.
** Error making
`Mercury/hlc.gc.tr/x86_64-unknown-linux-gnu/Mercury/cs/colgen_dw_new.c'.

which can be resolved by adding type specifications on two of the maps:
    impure ConvRows = ref.new(map.init : map(sp_id, int)),
    impure ActiveSP = ref.new(map.init : map(sp_id, set(sp_id))),

Why do I need to specify the type sometimes and sometimes type
inference works fine?

Cheers,
Jakob
--------------------------------------------------------------------------
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