Re: [MINOR SPOILER] Re: Perl Quiz of the Week #23
Matthew Walton <[email protected]>
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Daniel Martin wrote:
> Incidentally, my correspondence between binary trees and parenthesis
> strings is this, in pseudo-Haskell notation:
>
> string_for :: Tree a -> String
>
> string_for (Leaf _) = ""
> string_for (Branch l r) = "(" ++ string_for(l) ++ ")" ++ string_for(r)
>
> As I'm just learning Haskell myself, that may not be right. In
> English:
>
> The string for a leaf is "".
> The string for P, where P is not a leaf, is "(A)B", where A is the
> string for the left child of P and B is the string for the right.
Looks like you got the Haskell right to me... now all you need is the
tree to run the function on. Kind of interesting how you have a Tree a
but have absolutely no concern with what type a actually is, because you
never refer to any values of that type. I suppose you just want the tree
structure, rather than anything stored in it.
Sorry, rambling.