Gilgamesz
Gilgamesz

Reputation: 5073

Char to int. Haskell

I wonder if there is any function I described below is available in Prelude. Is it? (I know about ord, but it is in Data.Char)

I am looking for:

f :: Char -> Int
f 'a' = 0
f 'b' = 1
....

Upvotes: 0

Views: 445

Answers (1)

karakfa
karakfa

Reputation: 67507

f x = fromEnum x - fromEnum 'a'

Upvotes: 5

Related Questions