On 1/25/07, Brandon S. Allbery KF8NH <allbery@ece.cmu.edu> wrote:
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
(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