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
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] }
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] }
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
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,
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
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
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.
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
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
10 matches
Mail list logo