[m-dev.] instance declarations

Ian MacLarty maclarty at cs.mu.OZ.AU
Mon Mar 6 07:32:15 AEDT 2006


Hello,

Do we still need the restriction that types in instance declarations 
must be functors with distinct variables as arguments, even when some 
of those arguments are functionally dependent on other ones?  Surely 
you just need the arguments in the domain of the functional dependency 
to be functors?

The reason I ask is I was trying to rewrite Julien's rot13 stream 
library as follows:

:- pred rot13_stream.new(rot13_stream.name::in, Stream::in,
     rot13_stream::out) is det
     <= stream.output(Stream, char, State, Error).

:- func rot13_stream.name(rot13_stream) = string.

      % Encrypt a character.
      %
:- pred rot13_stream.put_char(rot13_stream(Stream)::in, char::in,
     State::di, State::uo) is det
     <= stream.output(Stream, char, State, Error).

:- instance stream.error(rot13_stream.error).
:- instance stream.stream(rot13_stream(Stream), State, 
rot13_stream.error).
:- instance stream.output(rot13_stream(Stream), char, State,
     rot13_stream.error).

, but of course I got an error with the instance declarations.  Here 
the first argument of the stream typeclass determines the the other two 
arguments, so surely it doesn't matter that the second argument (State) 
is a variable?

Ian.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list