
On 1/25/07, Brandon S. Allbery KF8NH
I'm probably missing something, but:
(a) Why not:
data ANode = Branch { name :: String, description :: String, children :: [AnyNode] } | Leaf { name :: String, value :: String } -- this reuse is legal -- leaving Node available if you still need it
Would I be able to this? getLeaves :: ANode -> [Leaf] If not, is it the case that people generally don't bother and do this instead? getLeaves :: ANode -> [ANode] (b) I think you *can* do this with a class:
class Node a where name :: a -> String
data Branch = Branch { brName :: String, ... } data Leaf = Leaf { lName :: String, ... }
instance Node Branch where name = brName
instance Node Leaf where name = lName
Okay, though it's a lot more wordy. -John