[Haskell-i18n] Some starters for the new list

Axel Simon A.Simon@ukc.ac.uk
Thu, 15 Aug 2002 14:09:39 +0100


On Thu, Aug 15, 2002 at 01:11:46PM +0100, Alastair Reid wrote:
> > (Naturally, the idea is that Prelude.fromString can be repaced by a
> > function that looks the string up in a translation table, instead of
> > using the default value.  Any reason this won't work?)
> 
> This goes quite a bit further than what I suggest above but let's try
> to sketch it out.
> 
> 1) You have to define a new string type:
> 2) You have to define an instance:

I think this is not really what was meant. The gettext C function takes a 
C String, looks it up in a translation table and returns a pointer with 
the translated string (or the original if no translation is found). AFAIK 
e.g. ghc does store string literals as C char* and not as a Haskell list. 
Thus the question is how to tell the compiler that it should use

peekCString (gettext strPtrToLiteral)

instead of 

peekCString strPtrToLiteral

for each string literal in the source code. We surely don't want to 
generate a Haskell list of characters, convert that back to a C string 
buffer, call gettext and convert the return value again to a Haskell list 
of Char.

Making string literals work with [Char] and PackedString is an orthogonal 
issue to i18n. This would involve introducing a class and instances.

When Haskell source files are read by character-set aware versions of 
readFile then ghc has to change in that string literals have to be stored 
in UTF-8 and accessed by something like peekUTF8String.

Axel.