Paul Hudak <[EMAIL PROTECTED]> writes:
> 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.
I'm afraid this doesn't work. There are two problems:
1) You need a constructor above:
> h1 (stringToHtml "This is a Header" (H1Args { align = Right}))
or
> H1 { align = Right, html = stringToHtml "This is a Header" }
2) Missing fields in a labeled field constructor are initialized to
_|_ (bottom). Thus, there's no safe way (in standard Haskell) to
differentiate between
> H1 { align = Right, html = stringToHtml "This is a Header" }
and
> H1 { html = stringToHtml "This is a Header" }
Attempts to extract the "align" field and do something with it in the
latter case will result in a run-time error.
Future versions of Haskell could address this using exception
handling, or by providing a default value for missing labels in
labeled field constructions.
Carl Witty