[Haskell-cafe] Trouble understanding records and existential types
John Ky
newhoggy at gmail.com
Wed Jan 24 19:34:55 EST 2007
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 a
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. Ideally I'd like the name field in the Node class, but it doesn't
seem that Haskell classes are for that sort of thing.
-John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070125/ba60d573/attachment.htm
More information about the Haskell-Cafe
mailing list