[Haskell-cafe] Rewriting Char.ord

PR Stanley prstanley at ntlworld.com
Sat Sep 29 10:37:21 EDT 2007


Okay, a couple of things
what is fromEnum?
What's the role of % in length 5 takeWhile (<c) ....
Thanks, Paul
At 15:26 29/09/2007, you wrote:
>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
>



More information about the Haskell-Cafe mailing list