Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell, Char, Unicode, and Turkish

For the Char data-type, how do I specify that I want to use the Turkish i instead of the English i for the toLower and toUpper functions?

like image 838
Jonathan Allen Avatar asked Aug 05 '10 07:08

Jonathan Allen


People also ask

What is a char in Haskell?

The character type Char is an enumeration whose values represent Unicode (or equivalently ISO 10646) characters.

How do you check if a character is a letter in Haskell?

You can use Data. Char. isAlpha to check that character is alphabet symbol.

How do you convert char to Int in Haskell?

A character literal in Haskell has type Char . To convert a Char to or from the corresponding Int value defined by Unicode, use toEnum and fromEnum from the Enum class respectively (or equivalently ord and chr ).


1 Answers

text and the text-icu package

As of 2011, your best bet is to use the text package, and the toLower function of the Text ICU package, which supports Char operations parameterized by a locale,

From this example:

import Data.Text (pack, unpack) import Data.Text.ICU (LocaleName(Locale), toLower)  main = do   let trLocale = Locale "tr-TR"       upStr    = "ÇIİĞÖŞÜ"       lowStr   = unpack $ toLower trLocale $ pack upStr   putStrLn $ "toLower " ++ upStr ++ " gives " ++ lowStr 

Running this:

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

while this example converts between String, you can also just leave the data in text format.

like image 81
Don Stewart Avatar answered Sep 19 '22 21:09

Don Stewart