Eddie
Eddie

Reputation: 891

Is there a function in Haskell that is the opposite of the ord function in Data.Char

i.e. it takes an Int and returns the corresponding Char for that Int i.e. 75 would return 'K'?

Upvotes: 4

Views: 2012

Answers (2)

Jason Dagit
Jason Dagit

Reputation: 13844

The answer to this question is chr as others have pointed out.

Frequently questions like this, "Does there exist a function Int -> Char?" can be quickly answered using Hoogle.

Searching hoogle for Int -> Char lists chr as the top match: http://www.haskell.org/hoogle/?hoogle=Int+-%3E+Char

Furthermore, in most browsers you can customize the address bar so that you can quickly search from your browser. In Chrome, go to Settings, "Manage search engines...", scroll to the bottom of the list and add "hoogle", "h", and "http://www.haskell.org/hoogle/?hoogle=%s" as an entry. Then you can go to the address bar, type "h Int -> Char" and it will take you to the results.

Upvotes: 10

bheklilr
bheklilr

Reputation: 54068

You're looking for the chr function in Data.Char

> :m Data.Char
> chr 75
'K'

Upvotes: 8

Related Questions