composewell / unicode-transforms

Fast Unicode normalization in Haskell
BSD 3-Clause "New" or "Revised" License
47 stars 16 forks source link

Incremental normalization? #60

Open jgm opened 3 years ago

jgm commented 3 years ago

According to its documentation, text-icu's collation algorithm uses incremental normalization. This is very helpful in collation: when you're comparing two strings, the decision about how to order them is generally one you can make after the first few characters, so no need to normalize the whole thing.

Could unicode-transforms provide a function that does this? For my purposes, an ideal interface would be

normalizeStreaming :: NormalizationMode -> Text -> [Int]

where the Ints are code points, and the list is produced lazily.

harendra-kumar commented 3 years ago

The best way to deal with this would be to use stream based normalization. Streamly is going to support that using a signature like this:

normalize :: (IsStream t, Monad m) => NormalizationMode -> t m Char -> t m Char

See this PR https://github.com/composewell/streamly/pull/698 for a working implementation of the above. We are also going to break streamly into several packages so that it can be a lightweight dependency and also have a streamly-unicode package for stream based unicode algorithms (see https://github.com/composewell/streamly/issues/533).

harendra-kumar commented 3 years ago

To work with text we can convert it to stream, normalize it and convert the stream back to text. In fact, with that we can work with any streamable type, not just text.

jgm commented 3 years ago

That sounds very good!