
9 Sep
2009
9 Sep
'09
8:10 a.m.
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