Hi all,
I have recently tried to replicate some examples from in the articles about type families but found some possible bugs.
In [2], the example
class C a where
type S a (k :: * -> *) :: *
instance C [a] where
type S [a] k = (a,k a)
does not compile under the claim that the type variable k is not in scope.
However, if we extract the type family from the class
type family S a (k :: * -> *) :: *
type instance S [a] k = (a, k a)
class C a
it compiles correctly.
According to [3], the difference is purely syntactic sugar, does that mean that both examples should compile and behave the same or is there some subtlety that justifies the class example not to compile?
Another issue is that data kinds (used in both [2] and [3]) do not seem to be supported at all by the compiler, are they already implemented in GHC?
Simple examples such as
datakind Nat = Zero
or
datakind Nat = Zero | Succ Nat
fail to compile.
Perhaps some of these should be submitted to the GHC Bug Tracker. I have tested both GHC 6.8.2 and 6.9.20080218.
References:
- Associated Types with Class. Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. In Proceedings of The 32nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'05), pages 1-13, ACM Press, 2005.
- Associated Type Synonyms. Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. In Proceedings of The Tenth ACM SIGPLAN International Conference on Functional Programming, ACM Press, pages 241-253, 2005.
- Towards Open Type Functions for Haskell. Tom Schrijvers, Martin Sulzmann, Simon Peyton-Jones, and Manuel M. T. Chakravarty. Unpublished manuscript, 2007.