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
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to