On Sat, Sep 29, 2007 at 03:11:20PM +0100, PR Stanley wrote:
> Hi
> ord :: Char -> Int
> ord c = sum [1 | x <- ['\0'..'\255'], x < c]
>
> Any comments? Any alternatives?
> Cheers, Paul

It's waay slow, it breaks for characters >255.

ord :: Char -> Int
ord = fromEnum

As Char is an instance of 'Enum'.

If you think this is cheating, then consider that (<) for Char is
probably implemented using ord on some level.  You need primitives
somewhere...

Stefan

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to