On 1/25/07, <b class="gmail_sendername">Brandon S. Allbery KF8NH</b> <<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm probably missing something, but:<br><br>(a) Why not:<br><br>data ANode = Branch { name :: String, description :: String,<br>children :: [AnyNode] }<br> | Leaf { name :: String, value :: String } -- this reuse
<br>is legal<br>-- leaving Node available if you still need it</blockquote><div><br>Would I be able to this?<br><br> getLeaves :: ANode -> [Leaf]<br><br>If not, is it the case that people generally don't bother and do this instead?
<br><br> getLeaves :: ANode -> [ANode]<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(b) I think you *can* do this with a class:
<br><br>class Node a where<br> name :: a -> String<br><br>data Branch = Branch { brName :: String, ... }<br>data Leaf = Leaf { lName :: String, ... }<br><br>instance Node Branch where<br> name = brName<br><br>instance Node Leaf where
<br> name = lName<br></blockquote></div><br>Okay, though it's a lot more wordy.<br><br>-John<br><br>