Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-03 Thread David Menendez
On Thu, May 1, 2008 at 4:10 PM, Daniil Elovkov [EMAIL PROTECTED] wrote: Felipe Lessa wrote: On Thu, May 1, 2008 at 9:44 AM, Felipe Lessa [EMAIL PROTECTED] wrote: On Thu, May 1, 2008 at 9:32 AM, Edsko de Vries [EMAIL PROTECTED] wrote: So then the question becomes: what *is* the

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-03 Thread Edsko de Vries
Hi, I think Huet's Zipper is intended to solve this sort of problem. data Path = Top | BranchL Path Tree | BranchR Tree Path type Zipper = (Path, Tree) openZipper :: Tree - Zipper openZipper t = (Top, t) Conceptually the zipper is a tree with one subtree selected. You can

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-03 Thread David Menendez
On Sat, May 3, 2008 at 12:30 PM, Edsko de Vries [EMAIL PROTECTED] wrote: I think Huet's Zipper is intended to solve this sort of problem. data Path = Top | BranchL Path Tree | BranchR Tree Path type Zipper = (Path, Tree) openZipper :: Tree - Zipper openZipper t =

[Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-01 Thread Edsko de Vries
Hi, Thanks to Miguel for pointing out my silly error. So at least my understanding of tail recursion is correct :) So then the question becomes: what *is* the best way to write this function? One version I can think of is ecount :: [Tree] - Integer - Integer ecount [] acc =

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-01 Thread Felipe Lessa
On Thu, May 1, 2008 at 9:32 AM, Edsko de Vries [EMAIL PROTECTED] wrote: So then the question becomes: what *is* the best way to write this function? I guess it would be simpler to have the counter on the data type and a smart branch constructor: data Tree = Leaf Integer | Branch Integer Tree

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-01 Thread Felipe Lessa
On Thu, May 1, 2008 at 9:44 AM, Felipe Lessa [EMAIL PROTECTED] wrote: On Thu, May 1, 2008 at 9:32 AM, Edsko de Vries [EMAIL PROTECTED] wrote: So then the question becomes: what *is* the best way to write this function? I guess it would be simpler to have the counter on the data type and

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-01 Thread Daniil Elovkov
Felipe Lessa wrote: On Thu, May 1, 2008 at 9:44 AM, Felipe Lessa [EMAIL PROTECTED] wrote: On Thu, May 1, 2008 at 9:32 AM, Edsko de Vries [EMAIL PROTECTED] wrote: So then the question becomes: what *is* the best way to write this function? I guess it would be simpler to have the counter on

Re: [Haskell-cafe] Re: Understanding tail recursion and trees

2008-05-01 Thread Derek Elkins
On Fri, 2008-05-02 at 00:10 +0400, Daniil Elovkov wrote: Felipe Lessa wrote: On Thu, May 1, 2008 at 9:44 AM, Felipe Lessa [EMAIL PROTECTED] wrote: On Thu, May 1, 2008 at 9:32 AM, Edsko de Vries [EMAIL PROTECTED] wrote: So then the question becomes: what *is* the best way to write this