[Haskell-cafe] Re: Type families not as useful over functions
Ahn, Ki Yung
kyagrd at gmail.com
Thu Feb 12 20:49:28 EST 2009
My thoughts on type families:
1) Type families are often too open. I causes "rigid variable"
type error messages because when I start writing open type
functions, I often realize that what I really intend is not
truly open type functions. It happens a lot that I had some
assumptions on the arguments or the range of the type function.
Then, we need help of type classes to constrain the result of
open type functions. For example, try to define HList library
using type families instead of type classes with functional
dependencies. One will soon need some class constraints.
Sometimes, we can use associated type families, but
many times it may become tedious when there are multiple
arguments and result have certain constraints so that
we might end up associating/splitting them over multiple
type classes. In such cases, it may be more simple working
with functional dependencies alone, rather than using
both type classes and type families. I wish we had closed
kinds so that we can define closed type functions as well as
open type functions.
2) Type families are not good when we need to match types
back and forth (e.g. bijective functions), or even multiple
ways. We need the help of functional dependencies for these
relational definitions. I know that several people are
working on the unified implementation for both type families
and functional dependencies. Once GHC have common background
implementation, type families will truly be syntactic sugar
of type classes with functional dependencies, as Mark Jones
advocates, or maybe the other way around too.
More information about the Haskell-Cafe