Paul Hudak wrote:
> 
> One alternative is to use labelled fields.  In your example, if Html
> were an algebraic datatype such as:
> 
> > data Html = Type1 { align = Align, ... }
> >           | Type2 { align = Align, ... }
> >           | ...
> 
> > data Align = Left | Right | Center
> 
> then instead of:
> 
> > h1 [align "right"] (stringToHtml "This is a Header")
> 
> you could write:
> 
> > h1 (stringToHtml "This is a Header" { align = Right})
> 
> or whatever, and you don't have the problem of dangling []'s,
> since stringToHtml would preesumably provide a default allignment,
> and it is legal to have the same label in different constructors.

Interesting!

Consider:

   h1 { inside = stringToHtml "This is a header" }

for the normal case, and
  
  h1 { align = "right", inside = stringToHtml "This is a header" }

for the case with alignment.

Adding some combinators:

(<<) :: Html -> Html -> Html
(<<) h1 h2 = h1 { inside = h2 }

and we get
  h1 << stringToHtml "This is a header"
  h1 { align = "right" } << stringToHtml "This is a header"

Now we've replaced [] with << :-)

However, this does seem more readable.

Andy



Reply via email to