Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: Char datatype

Char is used to store single Unicode character.

-- Unicode characters
char1, char2, char3 :: Char
char1 = 'a'
char2 = 'Ø'
char3 = 'ダ'

*Main> :load variable.hs
[1 of 1] Compiling Main ( variable.hs, interpreted )
Ok, modules loaded: Main.
*Main> char1
*Main> char2
*Main> char3

How to represent a character?
There are two ways to specify a charcater in Haskell.
         a. Specifying the character in signle quotes.
                  var1 = 'a'

         b. Specify the charcater by using the unicode value.
                  var2 = '\97'   -- in decimal

                  var3 = '\x61' -- in Hexa decimal
Prelude> let var1 = 'a'
Prelude> let var2 = '\97'
Prelude> let var3 = '\x61'
Prelude> var1
Prelude> var2
Prelude> var3

You can check the type of a variable using :t command.

Prelude> :t var1
var1 :: Char
Prelude> :t var3
var3 :: Char

Previous                                                 Next                                                 Home

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: Char datatype


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription