There are many SVG elements, of which only a few are valid as the content of each other SVG elements.
SvgDocumentElement defines the allowed subset for the SVG document.

I want to generate a "DList Char" for all those sub-elements and finally collapse them to one "DList Char" representing the whole SVG document.
So it's a bit more complicated than your "Either" example


I suggest a monadic combinator approach.  The grammar's the thing.

Consider:

> data View a = AtomicView a
>             | NestViews (View a) (View a) (View a)
>             | ConcatViews (View a) (View a)
>             | Etc...

> instance Monad View where
>    return = AtomicView
>    AtomicView v                  >>= f = f v
> (NestViews left middle right) >>= f = (ConcatViews (ConcatViews left middle) right) >>= f > (ConcatViews left right) >>= f = ConcatVeiws (f left) (f right)
> -- Etc                           >>= f = whatever

These are "structural" nodes. Notice how >>= normalizes your document automagically. You would put your specific node types "in" Etc. Writing a renderer from something with this form is pretty straight forward. Enforcing constraints isn't too hard either. Neither is parsing. Just write a parser for each

http://www.haskell.org/haskellwiki/Parsec
http://legacy.cs.uu.nl/daan/download/parsec/parsec.html
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to