[Haskell-cafe] pls help about subtree

Brent Yorgey byorgey at gmail.com
Tue Apr 29 10:35:08 EDT 2008


2008/4/28 cetin tozkoparan <cetintozkoparan at yahoo.com>:

> Assume a tree is a subtree of the other if all elements of the first tree
> is included in the second with the exact structure; all parent-child
> relations are preserved with their order.
>
> data Tree = Empty | Leaf Int | Node (Int,Tree,Tree)
> subtree:: Tree -> Tree -> Bool
>

Let me also point out that since you store an Int at each Node, there is no
need for the explicit Leaf constructor; for example, Leaf 5 can be
represented as  Node 5 Empty Empty.  Simplifying your data structure in this
way will make writing code for it much simpler and more elegant.

-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080429/1daf8d76/attachment.htm


More information about the Haskell-Cafe mailing list