Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-27 Thread Roberto Zunino
Brian Hulley wrote: Chris Kuklewicz wrote: This is how I would write getLeaves, based on your GADT: data IsLeaf data IsBranch newtype Node = Node { getNode :: (forall c. ANode c) } [snip] Thanks Chris - that's really neat! I see it's the explicit wrapping and unwrapping of the existential

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-26 Thread Udo Stenzel
John Ky wrote: On 1/25/07, BBrraannddoonn SS.. AAllllbbeerryy KKFF88NNHH [EMAIL PROTECTED] wrote: I'm probably missing something, but: (a) Why not: data ANode = Branch { name :: String, description :: String, children :: [AnyNode] }

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-25 Thread Brian Hulley
On Thursday, January 25, 2007 7:08 AM, John Ky wrote: On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: I'm probably missing something, but: (a) Why not: data ANode = Branch { name :: String, description :: String, children :: [AnyNode] }

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-25 Thread Chris Kuklewicz
This is how I would write getLeaves, based on your GADT: data IsLeaf data IsBranch newtype Node = Node { getNode :: (forall c. ANode c) } data ANode :: * - * where Branch :: String - String - (ANode a,ANode b) - [Node] - ANode IsBranch Leaf :: String - String - ANode IsLeaf

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-25 Thread John Ky
Let me try this option and see how I go. Thanks -John On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: (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,

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-25 Thread Brian Hulley
Chris Kuklewicz wrote: This is how I would write getLeaves, based on your GADT: data IsLeaf data IsBranch newtype Node = Node { getNode :: (forall c. ANode c) } data ANode :: * - * where Branch :: String - String - (ANode a,ANode b) - [Node] - ANode IsBranch Leaf :: String - String

[Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread John Ky
Hi, A while back I asked about OO programming in Haskell and discovered existential types. I understood that existential types allowed me to write heterogeneous lists which seemed sufficient at the time. Now trying to combine those ideas with records: data AnyNode = forall a. Node a = AnyNode

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread Brandon S. Allbery KF8NH
On Jan 24, 2007, at 19:34 , John Ky wrote: class Node -- yadda yadda data Branch = Branch { name :: String, description :: String, children :: [AnyNode] } data Leaf = Leaf { name :: String, value :: String } The problem here is I can't use the same 'name' field for both Branch and Leaf.

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread John Ky
On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] 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

Re: [Haskell-cafe] Trouble understanding records and existential types

2007-01-24 Thread Brandon S. Allbery KF8NH
On Jan 25, 2007, at 2:08 , John Ky wrote: On 1/25/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: data ANode = Branch { name :: String, description :: String, children :: [AnyNode] } | Leaf { name :: String, value :: String } -- this reuse is legal -- leaving Node available