Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

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

like image 688
Eddie Avatar asked Dec 02 '22 18:12

Eddie


2 Answers

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.

like image 70
Jason Dagit Avatar answered Dec 19 '22 18:12

Jason Dagit


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

> :m Data.Char
> chr 75
'K'
like image 36
bheklilr Avatar answered Dec 19 '22 17:12

bheklilr