Carl,
>>>>> "Carl" == Carl R Witty <[EMAIL PROTECTED]> writes:
Carl> 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.
Carl> I'm afraid this doesn't work. There are two problems:
Carl> 1) You need a constructor above:
>> h1 (stringToHtml "This is a Header" (H1Args { align = Right}))
Carl> or
>> H1 { align = Right, html = stringToHtml "This is a Header" }
h1 (stringToHtml "This is a Header") { align = AlignRight}
works if h1 and stringToHtml are as follows
stringToHtml s = Text { text = s }
h1 h = H1 { inside = h }
Carl> 2) Missing fields in a labeled field constructor are initialized to
Carl> _|_ (bottom). Thus, there's no safe way (in standard Haskell) to
Carl> differentiate between
>> H1 { align = Right, html = stringToHtml "This is a Header" }
Carl> and
>> H1 { html = stringToHtml "This is a Header" }
Carl> Attempts to extract the "align" field and do something with it in the
Carl> latter case will result in a run-time error.
But you could attach default alignment when converting any type to
Html
stringToHtml s = Text { align = defaultAlignment, text = s }
and propagate this as long as no other alignment is set, e.g
h1 h = H1 { align = align h, inside = h }
That way from
h1 (stringToHtml "Test") { align = AlignRight }
you get
H1{align=AlignRight,inside=Text{align=AlignRight,text="Test"}}
and from
(h1 (stringToHtml "Test")) { align = AlignRight }
you get
H1{align=AlignRight,inside=Text{align=AlignLeft,text="Test"}}
Marko
--
Marko Schütz [EMAIL PROTECTED]
http://www.ki.informatik.uni-frankfurt.de/~marko/