[mercury-users] odd warning..

Juergen Stuber juergen at mpi-sb.mpg.de
Wed Sep 22 03:26:53 AEST 1999


Rob <zharradan at suffering.org> writes:
> 
> I am getting a warning from the compiler that I have no idea how to go
> about fixing.. so I thought I would share with you to see if anyone can
> help :)
> 
> in handle_input.err:
> handle_input.m:043: In predicate `handle_input:convert_to_float/2':
> handle_input.m:043:   warning: unresolved polymorphism.
> handle_input.m:043:   The variable with an unbound type was:
> handle_input.m:043:       V_7 :: T
> handle_input.m:043:   The unbound type variable(s) will be implicitly
> handle_input.m:043:   bound to the builtin type `void'.
> 
> [..]
>
> % Convert a list of characters to a float
> convert_to_float(Word, F) :-
> 	string__from_char_list(Word, S_F),
> 	(   
> 	    string__to_float(S_F, F0) ->
> 	    F = F0
> 	;
> 	    % Bind F to something, to keep the compiler happy
> 	    F = 0.0,
> 	    display_error(_)
> 	).                ^
                          ^
The compiler couldn't figure out any type for the unused variable in
display_error/1 here -----^.  Since you don't use it that is no problem.
To remove the warning, you need a free variable of some type.  E.g.:

:- pred accept(univ).
:- mode accept(in) is det.
accept(_).

and then

      display_error(X),
      accept(X)
    ).

It would be nicer to attach a type to the variable, but AFAIK that
is not part of the language currently.


There are also some other good reasons to introduce typing for terms:
- to resolve ambiguities for typeclasses
- as hints for type inference for nested higher order functions and
  existential types

E.g. I think that the example for existential types

:- some [T] pred bad_e_bar2(T).
bad_e_bar2(42).
bad_e_bar2("blah").
        % type error (cannot unify types `int' and `string')

could be written as something like

:- some [T] pred e_bar2(T).
e_bar2(42 :: some [T] T).
e_bar2("blah" :: some [T] T).

Currently to achieve this effect you have to pack & unpack the
values into a constructor with an existentially quantified type
inside.

Greetings

Jürgen

-- 
Jürgen Stuber <juergen at mpi-sb.mpg.de>
http://www.mpi-sb.mpg.de/~juergen/
--------------------------------------------------------------------------
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