[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Design question

Subject: Re: [Haskell-cafe] Design question
From: Alexander Solla
Date: Mon, 28 Dec 2009 20:56:48 -0800


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

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
<Prev in Thread] Current Thread [Next in Thread>