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

Ralph Becket rafe at cs.mu.OZ.AU
Mon May 26 09:07:56 AEST 2003


Goncalo Jorge Coelho e Silva, Sunday, 25 May 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

Looking at this error message, I'd guess you've done something like

	NewReverseCodeList = some_function(...),
	io__print(NewReverseCodeList, IO6, IO7)

The dummy predicate in this situation may be necessary to determine the
type of NewReverseCodeList.  Any recent version of the compiler
(certainly 0.11 onwards) would allow you to use `with_type' instead.

However, looking further below I see what you've done...

(By the way, why not show us the predicate containing line 205?  Without
that context, it's very hard to say anything useful.)

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

chooseWord/9 is not mentioned anywhere in the error message.

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

Any name starting with a capital letter is taken to be a *VARIABLE*.
All other names have to start with a lower-case letter or an underscore.

Use a name like `new_reverse_code_list' instead.

> 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?)
> %

Why are you passing the IO state through this predicate?  It doesn't
appear to have any need to perform IO.

> chooseWord(ListIn, CodeAreaAddress, LabelHashIn, NextLabelHashOut,
> ReverseCodeList, CodeInstrListLine)-->
>         (
>         {ListIn=[]},
>         {NextLabelHashOut = LabelHashIn},
>         {CodeInstrListLine = ReverseCodeList}
>         ;
>         {ListIn=[H|[]]},

`[H | []]' is longhand for `[H]'.

>         {NextLabelHashOut = LabelHashIn},
>         {CodeInstrListLine = ReverseCodeList}
>         ;
>         {ListIn=[H|[NH|T]]},

`[H | [NH | T]]' is longhand for `[H, NH | T]'.

> [...]

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