[mercury-users] functional dependencies question

Mark Brown mark at cs.mu.OZ.AU
Thu Jan 19 13:59:02 AEDT 2006


On 18-Jan-2006, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
> On 17 Jan 2006, at 05:53, Mark Brown wrote:
> 
> >Hi Ian,
> >
> >On 16-Jan-2006, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
> >>Hello,
> >>
> >>Why will a program with the following typeclass definitions not 
> >>compile?
> >>
> >>:- typeclass tc1(S, T) <= (S -> T) where [
> >>	pred mem1(S::in, S::out) is det
> >>].
> >>
> >>:- typeclass tc2(S, T) <= tc1(S, T) where [
> >>	pred mem2(S::in, S::out) is det
> >>].
> >>
> >>:- typeclass tc3(S) <= tc1(S, T) where [].
> >>
> >>For tc2 shouldn't the compiler be able to infer that T is functionally
> >>dependent on S, so mem2 is fine?
> >
> >It would be able to infer that, but a deliberate design decision was
> >made to require the FDs on subclasses to be explicit.  The rationale
> >is that forcing them to be explicit would make code easier to
> >understand and reason about.
> >
> >However, I don't consider this rationale to be particularly strong.  
> >There
> >seems to be a bit of a "surprise" factor with this restriction, so I 
> >could
> >be persuaded that it would be okay to drop it.  (I was undecided about
> >this when I implemented it, so it seemed best to be conservative.)
> >
> 
> I don't think it hurts to require the functional dependencies to be 
> explicit in subclasses and I think it does make the code clearer.  On 
> the other hand it is a bit unintuitive, since you're not required to 
> explicitly list all the other superclass constraints.

Hmm, good point.

> I don't yet have 
> enough experience to say one way or the other, so I suggest you leave 
> it as is for now, unless someone else has any strong opinions.  I think 
> at least though the documentation should say that they must be 
> explicitly given for subclasses.

And the error message too, I guess.

Cheers,
Mark.

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