Case Mapping for Turkish in Haskell

Turkish is generally challenging for i18n related software particularly because of its special case for the I, ı, İ, i letters. The problem is discussed in detail here

.

Haskell has recently got complete support for various Unicode services through text

and text-icu packages. Some recent updates to text and text-icu are explained in the author’s blog .

The following is a Haskell code snippet which shows an example of case mapping for Turkish using the mentioned packages.

1
2
3
4
5
6
7
8
import Data.Text (pack, unpack)
import Data.Text.ICU (LocaleName(Locale), toLower)

main = do
  let trLocale = Locale "tr-TR"
  let upStr = "ÇIİĞÖŞÜ"
  let lowStr = unpack $ toLower trLocale $ pack upStr
  putStrLn $ "toLower " ++ upStr ++ " gives " ++ lowStr

The program simply outputs (as expected):

1
toLower ÇIİĞÖŞÜ gives çıiğöşü

Perhaps one thing that needs to be explained regarding this code is that pack and unpack are used there for converting from String to Text and vise-versa as required by the packages we use.

Although the code is a little bit imperative (well, I am new to Haskell ;-) ) it should give an idea of how to use the functionality for Turkish or any other language or locale.

One thought on “Case Mapping for Turkish in Haskell

  1. Nice work, Ersin. I posted a refinement on my own blog at http://www.serpentine.com/blog/2010/09/27/a-tiny-example-of-clean-unicode-handling-in-haskell/

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>