
Please forgive me if I'm still mentally contaminated by the OO way of seeing (and discussing) the universe, but I'm trying to figure out how to "inherit an interface" from a multi-parameter type class. I have a Graph class that's parameterisable by Node and Edge type: class (Node a, Edge b) => Graph a b where (lots of stuff that you can do with Graph a b) Now, I'd like to build a FooGraph on top of this that adds additional capabilities: class (Graph a b) => FooGraph a b where (lots of additional stuff) but this isn't allowed (kind mismatch). Of couse, I can do: class (Node a, Edge b) => FooGraph a b but this means that I have to manually replicate the Graph a b operations in the FooGraph a b class definition, which is (a) work that the machine should (?) be able to do for me, and (b) fragile. Any pointers / wisdom would be very much appreciated. - Derek

There's nothing wrong with the definition of FooGraph. That's how you do it.
-- Lennart
On Tue, Feb 24, 2009 at 6:09 PM, Derek Gladding
Please forgive me if I'm still mentally contaminated by the OO way of seeing (and discussing) the universe, but I'm trying to figure out how to "inherit an interface" from a multi-parameter type class.
I have a Graph class that's parameterisable by Node and Edge type:
class (Node a, Edge b) => Graph a b where (lots of stuff that you can do with Graph a b)
Now, I'd like to build a FooGraph on top of this that adds additional capabilities:
class (Graph a b) => FooGraph a b where (lots of additional stuff)
but this isn't allowed (kind mismatch).
Of couse, I can do:
class (Node a, Edge b) => FooGraph a b
but this means that I have to manually replicate the Graph a b operations in the FooGraph a b class definition, which is (a) work that the machine should (?) be able to do for me, and (b) fragile.
Any pointers / wisdom would be very much appreciated.
- Derek
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks to the kind replies I got off-list, I figured out that this was actually operator error on my part. class (Node a, Edge b) => Graph a b was actually class (Node a, Edge b) => Graph g a b but this was in code I'd written quite some time ago and I've written a lot of day-job C++ in the intervening period. Main lesson learned: Read the ghc error message carefully, it contains all the information you need. Thankyou once again. - Derek Derek Gladding wrote:
Please forgive me if I'm still mentally contaminated by the OO way of seeing (and discussing) the universe, but I'm trying to figure out how to "inherit an interface" from a multi-parameter type class.
I have a Graph class that's parameterisable by Node and Edge type:
class (Node a, Edge b) => Graph a b where (lots of stuff that you can do with Graph a b)
Now, I'd like to build a FooGraph on top of this that adds additional capabilities:
class (Graph a b) => FooGraph a b where (lots of additional stuff)
but this isn't allowed (kind mismatch).
Of couse, I can do:
class (Node a, Edge b) => FooGraph a b
but this means that I have to manually replicate the Graph a b operations in the FooGraph a b class definition, which is (a) work that the machine should (?) be able to do for me, and (b) fragile.
Any pointers / wisdom would be very much appreciated.
- Derek
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Derek Gladding wrote:
Please forgive me if I'm still mentally contaminated by the OO way of seeing (and discussing) the universe, but I'm trying to figure out how to "inherit an interface" from a multi-parameter type class. [...] but this isn't allowed (kind mismatch).
Kinds are a meta-type system for types. Because Haskell has such a rich type system, the types themselves need a type-like system. These are "kinds". You never declare kinds (apart from certain language extensions not in use here): the compiler infers them. This suggests that your problem is in the types lower down. Probably you are using "a" or "b" in a way that implies they take a type argument in one place (kind * -> *) and not in another place (kind *).

On 02/24/09 13:41, Paul Johnson wrote:
Derek Gladding wrote:
Please forgive me if I'm still mentally contaminated by the OO way of seeing (and discussing) the universe, but I'm trying to figure out how to "inherit an interface" from a multi-parameter type class. [...] but this isn't allowed (kind mismatch).
Kinds are a meta-type system for types. Because Haskell has such a rich type system, the types themselves need a type-like system. These are "kinds". You never declare kinds (apart from certain language extensions not in use here): the compiler infers them.
Is a kind sorta like a type universe as in nuprl: http://www.cs.cornell.edu/home/sfa/Nuprl/NuprlPrimitives/Xuniverse_doc.html Except that a kind sounds like a universe at level 2 or 3. IOW, I guess haskell types are at level 1, and kines at level 2? Then I guess values would be at level 0? Is there some version of haskell that has more levels in its type universe. If not, it there some reason for that limitation? Is there some reference explaining the relationship of haskell types to nuprl type universes? TIA. -Larry

Larry Evans wrote:
Except that a kind sounds like a universe at level 2 or 3. IOW, I guess haskell types are at level 1, and kines at level 2? Then I guess values would be at level 0?
Exactly.
Is there some version of haskell that has more levels in its type universe. If not, it there some reason for that limitation?
The language you're looking for is called Omega: http://web.cecs.pdx.edu/~sheard/Omega/index.html http://code.google.com/p/omega/ http://web.cecs.pdx.edu/~sheard/ And as the name implies, the levels go all the way to the top.
Is there some reference explaining the relationship of haskell types to nuprl type universes?
That one I can't help with :) -- Live well, ~wren
participants (5)
-
Derek Gladding
-
Larry Evans
-
Lennart Augustsson
-
Paul Johnson
-
wren ng thornton