I have a question regarding class definition with polymorphic data types. Lets say the defined datatype is:
data BTree a = BLeaf a | BNode a (BTree a) (BTree a) deriving(Show)
Lets say I want to retrieve the value of the root of the tree, but within an instance of a class called Tree:
class Tree a where
getRoot:: a -> (?) --<- Type of Leave value as return type
and an instance:
instance Tree (BTree a) where
getRoot BLeaf a = a
getRoot BNode a _ _ = a
I can't figure out the type of the function (see questionmark), since its not a and the class doesn't know the parameter of the instance.