
People, I need to convert Char <-> Int in a possibly _standard_ way for Haskell -- and also in an efficient way. In particular, it must not spend 100 comparisons in a look through the listing of Char. I use ord :: Char -> Int and chr :: Int -> Char. Is this all right? Thank you in advance for advice, ----------------- Serge Mechveliani mechvel@botik.ru

mechvel:
People, I need to convert Char <-> Int in a possibly _standard_ way for Haskell -- and also in an efficient way. In particular, it must not spend 100 comparisons in a look through the listing of Char.
I use ord :: Char -> Int and chr :: Int -> Char.
ord and chr are correct, yes. ord :: Char -> Int ord (C# c#) = I# (ord# c#) chr :: Int -> Char chr (I# i#) | int2Word# i# `leWord#` int2Word# 0x10FFFF# = C# (chr# i#) | otherwise = error "Prelude.chr: bad argument" unsafeChr :: Int -> Char unsafeChr (I# i#) = C# (chr# i#) These are usually resolved at compile time as casts. -- Don
participants (2)
-
Don Stewart
-
Serge D. Mechveliani