[mercury-users] ambiguous overloading causes type ambiguity.

Ralph Becket rbeck at microsoft.com
Mon Apr 30 20:14:01 AEST 2001


> :- module divisors.
> :- interface.
> :- import_module io.
> 
> :- pred main(io__state::di, io__state::uo) is det.
> 
> :- implementation.
> :- import_module std_util, int, list, bool, string.
> 
> main --> io__read_line_as_string(W0),
>      (
> 	{ W0 = eof },
> 	print("Nothing could be read"), nl
> 	;
> 	{ W0 = error(Err) },
> 	print(io__error_message(Err)), nl

io__error_message(Err) can be interpreted either as a nullary closure
(pred)
or as a string (the result of the application of io__error_message to
Err).
Since io__print//1 is polymorphic in its first argument, the compiler
has
no contextual information to tell it which interpretation is correct.
The
type checker insists on having unambiguous types at every point in a
program,
hence the complaint.

The easiest solution is to add an explicit type declaration:

	io__print(io__error_message(Err) `with_type` string),

> 	;
> 	{ W0 = ok(W),
> 	  I = string__det_to_int(W) },
> 	  io__write_string(test(I))

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