Designing an object model in Haskell

Hi, I've got an object model that I have a difficult time conceptualising how it might look like in Haskell: class Element { } class Inline : Element { } class ParentInline : Inline { List<Inline> children; } class Bold : ParentInline { } class Underline : ParentInline { } class Link : ParentInline { String link; } class Text : Inline { String text; } class Block : Element { } class Paragraph : Block { List<Inline> paragraph; } class Heading : Block { List<Inline> heading; } class Document : Element { List<Block> blocks; } How best to represent this OO data model in Haskell? Thanks -John

John Ky wrote:
Hi,
I've got an object model that I have a difficult time conceptualising how it might look like in Haskell:
class Element { }
class Inline : Element { }
class ParentInline : Inline { List<Inline> children; }
class Bold : ParentInline { } class Underline : ParentInline { }
class Link : ParentInline { String link; }
class Text : Inline { String text; }
class Block : Element { }
class Paragraph : Block { List<Inline> paragraph; }
class Heading : Block { List<Inline> heading; }
class Document : Element { List<Block> blocks; }
How best to represent this OO data model in Haskell? You could, depending on what you intend to do, model a hierarchical document type something like this (if I read your model correctly):
type Document = [Block] data Block = Heading [Inline] | Paragraph [Inline] data Inline = Text String | ParentInline data ParentInline = PIL PILType [Inline] data PILType = Bold | Underline | Link String Does that fit? -k

Have you looked at OOHaskell (http://homepages.cwi.nl/~ralf/OOHaskell/)? -Jeff haskell-cafe-bounces@haskell.org wrote on 12/07/2006 07:07:46 AM:
Hi,
I've got an object model that I have a difficult time conceptualising how it might look like in Haskell:
class Element { }
class Inline : Element { }
class ParentInline : Inline { List<Inline> children; }
class Bold : ParentInline { } class Underline : ParentInline { }
class Link : ParentInline { String link; }
class Text : Inline { String text; }
class Block : Element { }
class Paragraph : Block { List<Inline> paragraph; }
class Heading : Block { List<Inline> heading; }
class Document : Element { List<Block> blocks; }
How best to represent this OO data model in Haskell?
Thanks
-John _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
--- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

John, For the particular object model that you are interested in (an HTML- ish object model), you should check out the paper by Peter Thiemann entitled "A Typed Representation for HTML and XML Documents in Haskell". -- Robin Bate Boerop http://robin.bateboerop.name On 7-Dec-06, at 8:07 AM, John Ky wrote:
Hi,
I've got an object model that I have a difficult time conceptualising how it might look like in Haskell:
class Element { }
class Inline : Element { }
class ParentInline : Inline { List<Inline> children; }
class Bold : ParentInline { } class Underline : ParentInline { }
class Link : ParentInline { String link; }
class Text : Inline { String text; }
class Block : Element { }
class Paragraph : Block { List<Inline> paragraph; }
class Heading : Block { List<Inline> heading; }
class Document : Element { List<Block> blocks; }
How best to represent this OO data model in Haskell?
Thanks
-John
participants (4)
-
Jeff Polakow
-
John Ky
-
Ketil Malde
-
Robin Bate Boerop