[Haskell] Unicode advice request

Don Stewart dons at galois.com
Fri Mar 14 14:40:30 EDT 2008


kalman:
> Excuse me if this question is misplaced or too trivial.
> 
> I'm writing a CGI program in Haskell (CGI/HDBC/Sqlite3), the database 
> contains  UTF-8 strings.  If I use HDBC.fetchRow() to retrieve the data, 
> then HDBC.fromSql() to convert the data to Haskell, then Text.XHtml 
> constructs to dsplay it, I get wrong results in the browser (ASCII 
> rendering of UTF-8 characters, which looks like garbage).  What is the 
> way to do this correctly?

You may need to write the strings to the database using the utf8-string
package.

Also, if you're never actually decoding the data, it may be your CGI app
generating a page with the wrong content type. When starting up your CGI
app, set the content type to utf8,

    main  = runFastCGIorCGI  $ ...
        setHeader "Content-type" "text/plain; charset=utf-8"
        ...

So check the headers being generated are of the correct type.

Cheers, 
  Don


More information about the Haskell mailing list