Example for formatted show in HStringTemplate

Hello, is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.: $day;format="%d.%b.%Y"$ But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show. Regards, Torsten

+++ Kemps-Benedix Torsten [Jul 13 09 23:56 ]:
Hello,
is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.:
$day;format="%d.%b.%Y"$
But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show.
You probably need to define a StringTemplateShows instance for Data.Time.Day, and then use stShowsToSE to define a ToSElem instance. Something like instance StringTemplateShows Day where stringTemplateFormattedShow formatString = formatTime defaultTimeLocale formatString {- or whatever -- I'm not sure what the correct time-formatting function is -} instance ToSElem Day where toSElem = stShowsToSE John

John, thanks for your answer, but HStringtemplate has instance definitions for Date.Time.Day. The question is more on the script side: How do I have to write the ST calls with ";format=" embedded in HTML? regards, Torsten -----Ursprüngliche Nachricht----- Von: John MacFarlane [mailto:fiddlosopher@gmail.com] Gesendet: Dienstag, 14. Juli 2009 08:20 An: Kemps-Benedix Torsten Cc: HAppS@googlegroups.com; haskell-cafe@haskell.org Betreff: Re: Example for formatted show in HStringTemplate +++ Kemps-Benedix Torsten [Jul 13 09 23:56 ]:
Hello,
is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.:
$day;format="%d.%b.%Y"$
But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show.
You probably need to define a StringTemplateShows instance for Data.Time.Day, and then use stShowsToSE to define a ToSElem instance. Something like instance StringTemplateShows Day where stringTemplateFormattedShow formatString = formatTime defaultTimeLocale formatString {- or whatever -- I'm not sure what the correct time-formatting function is -} instance ToSElem Day where toSElem = stShowsToSE John

What I suspect that you've encountered is an infelicity when importing GenericStandard. The ToSElem instance defaults to that provided by (Data a) context. However, there is no special handler for Data.Time types in the `extQ` chain. I could add one, but that would require relying on the Data.Time library being the latest (since Typeable isn't provided until then) or on conditional compilation and standalone deriving, which is a pain. As the new time package comes into widespread use, I'll fix up the gToSElem function with the appropriate handlers, but until then I'm afraid that standard generics won't play well with Data.Time. GenericWithClass, on the other hand, might yield better results. There is, by the way, (thanks to the efforts of Luke Plant) now an HStringTemplate page on the haskellwiki: http://www.haskell.org/haskellwiki/HStringTemplate. Edits, improvements, etc. of course welcome by all. You may want to post this question and answer there. By the way, I plan to have a new version with a real announcement and a fair share of bugfixes in the next week or so. Cheers, Sterl. Kemps-Benedix Torsten wrote:
John,
thanks for your answer, but HStringtemplate has instance definitions for Date.Time.Day. The question is more on the script side: How do I have to write the ST calls with ";format=" embedded in HTML?
regards,
Torsten
-----Ursprüngliche Nachricht----- Von: John MacFarlane [mailto:fiddlosopher@gmail.com] Gesendet: Dienstag, 14. Juli 2009 08:20 An: Kemps-Benedix Torsten Cc: HAppS@googlegroups.com; haskell-cafe@haskell.org Betreff: Re: Example for formatted show in HStringTemplate
+++ Kemps-Benedix Torsten [Jul 13 09 23:56 ]:
Hello,
is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.:
$day;format="%d.%b.%Y"$
But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show.
You probably need to define a StringTemplateShows instance for Data.Time.Day, and then use stShowsToSE to define a ToSElem instance. Something like
instance StringTemplateShows Day where stringTemplateFormattedShow formatString = formatTime defaultTimeLocale formatString {- or whatever -- I'm not sure what the correct time-formatting function is -}
instance ToSElem Day where toSElem = stShowsToSE
John _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/Example-for-formatted-show-in-HStringTemplate-tp244704... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Torsten, I'm not quite sure what you're asking -- but this simple example seems to work fine: Prelude Text.StringTemplate> let (a :: StringTemplate String) = newSTMP "$day;format=\"%d.%b.%Y\"$" Prelude Text.StringTemplate Data.Time> render $ setAttribute "day" (ModifiedJulianDay 234) a "09.Jul.1859" John +++ Kemps-Benedix Torsten [Jul 14 09 12:20 ]:
John,
thanks for your answer, but HStringtemplate has instance definitions for Date.Time.Day. The question is more on the script side: How do I have to write the ST calls with ";format=" embedded in HTML?
regards,
Torsten
-----Ursprüngliche Nachricht----- Von: John MacFarlane [mailto:fiddlosopher@gmail.com] Gesendet: Dienstag, 14. Juli 2009 08:20 An: Kemps-Benedix Torsten Cc: HAppS@googlegroups.com; haskell-cafe@haskell.org Betreff: Re: Example for formatted show in HStringTemplate
+++ Kemps-Benedix Torsten [Jul 13 09 23:56 ]:
Hello,
is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.:
$day;format="%d.%b.%Y"$
But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show.
You probably need to define a StringTemplateShows instance for Data.Time.Day, and then use stShowsToSE to define a ToSElem instance. Something like
instance StringTemplateShows Day where stringTemplateFormattedShow formatString = formatTime defaultTimeLocale formatString {- or whatever -- I'm not sure what the correct time-formatting function is -}
instance ToSElem Day where toSElem = stShowsToSE
John _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
John MacFarlane
-
Kemps-Benedix Torsten
-
Sterling Clover