MPTCs and functional dependencies

Ravi Nanavati ravi at bluespec.com
Thu Feb 2 09:26:28 EST 2006


Henrik Nilsson wrote:
> Dear all,
> 
> Simon PJ wrote:
> 
>  > Multi-parameter type classes, yes.  Functional dependencies, no.
> 
> My experience is that even with very simple applications of MPTCs,
> I often end up needing functional dependencies to make things work.

As a user, I'll echo this. It seems to me that when you create a 
multi-parameter typeclass, there are often constraints among the 
different parameters that need to be expressed. As an example, consider 
writing a multi-parameter typeclass to capture the idea of being able to 
"select" an object out of an indexed collection (e.g. a list or an 
array). One dependency you'd like to have might be that the collection 
type determines the type of the item you're selecting (so that the type 
of the item can be inferred from the type of the collection).

As a second data point, I looked at the monad transformer library. The 
multi-parameter classes MonadState, MonadError, MonadReader and 
MonadWriter all use functional dependencies among their parameters. I 
think monad transformers are a significant part of the motivation to 
include multi-parameter typeclasses. This, to me, implies that we need 
some answer for their use of functional dependencies.

  - Ravi


More information about the Haskell-prime mailing list