[mercury-users] type ambiguity (dummy predicate use)

Goncalo Jorge Coelho e Silva l10454 at alunos.uevora.pt
Mon May 26 08:51:35 AEST 2003



Hi again,

 I got this demand from the compiler that I should use
a 'dummy' predicate declaration to resolve an ambiguity
(sort of strange one - why is there an ambiguity in the
first place?).

 Appearantly, my list is being mistaken with a predicate.

 I'll post the code bellow for assistance (I apologise if
the code chunk might not be that clear :( ):


error:
------

inter.m:205: NewReverseCodeList :: (pred (list:list((inter:instruction))))
or (list:list((inter:instruction)))
        You will need to add an explicit type qualification to resolve the
        type ambiguity.
        The way to add an explicit type qualification
        is to insert a call to a dummy predicate whose `:- pred'
        declaration specifies the appropriate argument types.
inter.m:198: Inferred :- pred ''(T1, T2, (io:state), (io:state)).
make: *** [run] Error 1


problematic predicate declaration:
--------------------------

:- pred chooseWord(list(string), int, hash_table(string, int),
      hash_table(string, int), instruction, list(instruction),
      list(instruction), io__state, io__state).
:- mode chooseWord(in, in, in(hash_table), out(hash_table), out, in, out,
      di, uo) is det.



my 'dummy' predicates:
------------------------------------------

%:- pred dummy(list(instruction)::in, io::di, io::uo) is semidet.
%:- pred dummy(list(instruction), io__state, io__state).
%:- mode dummy(in, in, out) is semidet.
:- pred NewReverseCodeList(list(instruction), io__state, io__state).
:- mode NewReverseCodeList(in, in, out) is semidet.




versions for problematic predicate:
----------------------------------------------

%% input: List of words separated by a whitespace taken from an instruction row
%  output: a list of 'instruction' type items
%  descritpion: Goes through the list and identifies the instruction
(e.g.Label?)
%
chooseWord(ListIn, CodeAreaAddress, LabelHashIn, NextLabelHashOut,
ReverseCodeList, CodeInstrListLine)-->
        (
        {ListIn=[]},
        {NextLabelHashOut = LabelHashIn},
        {CodeInstrListLine = ReverseCodeList}
        ;
        {ListIn=[H|[]]},
        {NextLabelHashOut = LabelHashIn},
        {CodeInstrListLine = ReverseCodeList}
        ;
        {ListIn=[H|[NH|T]]},
        chooseInstruct(H, NH, CodeAreaAddress, LabelHashIn, LabelHashOut,
CodeAreaInstr),
        {list__append(ReverseCodeList, [CodeAreaInstr]) =
NewReverseCodeList},
        chooseWord(T, CodeAreaAddress, LabelHashOut, NextLabelHashOut,
NewReverseCodeList, CodeI
        ).




or, using another approach:




  chooseWord(ListIn, CodeAreaAddress, LabelHashIn, NextLabelHashOut,
ReverseCodeList, CodeInstrListLine)-->
        (
        {ListIn=[]},
        {NextLabelHashOut = LabelHashIn},
        {CodeInstrListLine = list__reverse(ReverseCodeList)},
        ;
        {ListIn=[H|[]]},
        {NextLabelHashOut = LabelHashIn},
        {CodeInstrListLine = list__reverse(ReverseCodeList)}
        ;
        {ListIn=[H|[NH|T]]},
        chooseInstruct(H, NH, CodeAreaAddress, LabelHashIn, LabelHashOut,
CodeAreaInstr),
        chooseWord(T, CodeAreaAddress, LabelHashOut, NextLabelHashOut,
[CodeAreaInstr | ReverseCodeList], CodeInstrListLine)
        ).



thanks a lot,
Goncalo


--------------------------------------------------------------------------
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