nri-prelude
Safe HaskellNone
LanguageHaskell2010

Char

Description

Functions for working with characters. Character literals are enclosed in 'a' pair of single quotes.

Since we don't have a browser and we don't have a default locale, functions like toLocaleUpper and toLocaleUpper are not supported. If you need something like that you can check out the 'text-icu' package which provides functions like toUpper :: LocaleName -> Text -> Text.

Synopsis

Characters

data Char #

The character type Char represents Unicode codespace and its elements are code points as in definitions D9 and D10 of the Unicode Standard.

Character literals in Haskell are single-quoted: 'Q', 'Я' or 'Ω'. To represent a single quote itself use '\'', and to represent a backslash use '\\'. The full grammar can be found in the section 2.6 of the Haskell 2010 Language Report.

To specify a character by its code point one can use decimal, hexadecimal or octal notation: '\65', '\x41' and '\o101' are all alternative forms of 'A'. The largest code point is '\x10ffff'.

There is a special escape syntax for ASCII control characters:

EscapeAlternativesMeaning
'\NUL''\0'null character
'\SOH''\1'start of heading
'\STX''\2'start of text
'\ETX''\3'end of text
'\EOT''\4'end of transmission
'\ENQ''\5'enquiry
'\ACK''\6'acknowledge
'\BEL''\7', '\a'bell (alert)
'\BS''\8', '\b'backspace
'\HT''\9', '\t'horizontal tab
'\LF''\10', '\n'line feed (new line)
'\VT''\11', '\v'vertical tab
'\FF''\12', '\f'form feed
'\CR''\13', '\r'carriage return
'\SO''\14'shift out
'\SI''\15'shift in
'\DLE''\16'data link escape
'\DC1''\17'device control 1
'\DC2''\18'device control 2
'\DC3''\19'device control 3
'\DC4''\20'device control 4
'\NAK''\21'negative acknowledge
'\SYN''\22'synchronous idle
'\ETB''\23'end of transmission block
'\CAN''\24'cancel
'\EM''\25'end of medium
'\SUB''\26'substitute
'\ESC''\27'escape
'\FS''\28'file separator
'\GS''\29'group separator
'\RS''\30'record separator
'\US''\31'unit separator
'\SP''\32', ' 'space
'\DEL''\127'delete

Data.Char provides utilities to work with Char.

Instances

Instances details
FromJSON Char # 
Instance details

Defined in Data.Aeson.Types.FromJSON

FromJSONKey Char # 
Instance details

Defined in Data.Aeson.Types.FromJSON

ToJSON Char # 
Instance details

Defined in Data.Aeson.Types.ToJSON

ToJSONKey Char # 
Instance details

Defined in Data.Aeson.Types.ToJSON

IsChar Char #

Since: base-2.1

Instance details

Defined in Text.Printf

Methods

toChar :: Char -> Char #

fromChar :: Char -> Char #

PrintfArg Char #

Since: base-2.1

Instance details

Defined in Text.Printf

NFData Char # 
Instance details

Defined in Control.DeepSeq

Methods

rnf :: Char -> () #

ToJExpr Char # 
Instance details

Defined in GHC.JS.Make

HasChar Char 
Instance details

Defined in GHC.Parser.String

Methods

getChar :: Char -> Char

setChar :: Char -> Char -> Char

Binary Char # 
Instance details

Defined in GHC.Utils.Binary

ToJson String # 
Instance details

Defined in GHC.Utils.Json

Methods

json :: String -> JsonDoc #

Bounded Char #

Since: base-2.1

Instance details

Defined in GHC.Internal.Enum

Enum Char #

Since: base-2.1

Instance details

Defined in GHC.Internal.Enum

Methods

succ :: Char -> Char #

pred :: Char -> Char #

toEnum :: Int -> Char #

fromEnum :: Char -> Int #

enumFrom :: Char -> [Char] #

enumFromThen :: Char -> Char -> [Char] #

enumFromTo :: Char -> Char -> [Char] #

enumFromThenTo :: Char -> Char -> Char -> [Char] #

Read Char #

Since: base-2.1

Instance details

Defined in GHC.Internal.Read

Show Char #

Since: base-2.1

Instance details

Defined in GHC.Internal.Show

Methods

showsPrec :: Int -> Char -> ShowS #

show :: Char -> String #

showList :: [Char] -> ShowS #

Eq Char # 
Instance details

Defined in GHC.Classes

Methods

(==) :: Char -> Char -> Bool #

(/=) :: Char -> Char -> Bool #

Ord Char # 
Instance details

Defined in GHC.Classes

Methods

compare :: Char -> Char -> Ordering #

(<) :: Char -> Char -> Bool #

(<=) :: Char -> Char -> Bool #

(>) :: Char -> Char -> Bool #

(>=) :: Char -> Char -> Bool #

max :: Char -> Char -> Char #

min :: Char -> Char -> Char #

Hashable Char # 
Instance details

Defined in Data.Hashable.Class

Methods

hashWithSalt :: Int -> Char -> Int #

hash :: Char -> Int #

IsText String # 
Instance details

Defined in Data.Text.Lens

Uniform Char # 
Instance details

Defined in System.Random.Internal

Methods

uniformM :: StatefulGen g m => g -> m Char #

UniformRange Char # 
Instance details

Defined in System.Random.Internal

Methods

uniformRM :: StatefulGen g m => (Char, Char) -> g -> m Char #

Validity Char #

Trivially valid

Instance details

Defined in Data.Validity

Methods

validate :: Char -> Validation #

Unbox Char # 
Instance details

Defined in Data.Vector.Unboxed.Base

Pretty Char # 
Instance details

Defined in Text.PrettyPrint.Annotated.WL

Methods

pretty :: Char -> Doc b #

prettyList :: [Char] -> Doc b #

TestCoercion SChar #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeLits

Methods

testCoercion :: forall (a :: Char) (b :: Char). SChar a -> SChar b -> Maybe (Coercion a b) #

TestEquality SChar #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeLits

Methods

testEquality :: forall (a :: Char) (b :: Char). SChar a -> SChar b -> Maybe (a :~: b) #

Vector Vector Char # 
Instance details

Defined in Data.Vector.Unboxed.Base

MVector MVector Char # 
Instance details

Defined in Data.Vector.Unboxed.Base

Cons Text Text Char Char # 
Instance details

Defined in Control.Lens.Cons

Methods

_Cons :: Prism Text Text (Char, Text) (Char, Text) #

Cons Text Text Char Char # 
Instance details

Defined in Control.Lens.Cons

Methods

_Cons :: Prism Text Text (Char, Text) (Char, Text) #

Snoc Text Text Char Char # 
Instance details

Defined in Control.Lens.Cons

Methods

_Snoc :: Prism Text Text (Text, Char) (Text, Char) #

Snoc Text Text Char Char # 
Instance details

Defined in Control.Lens.Cons

Methods

_Snoc :: Prism Text Text (Text, Char) (Text, Char) #

Generic1 (URec Char :: k -> Type) # 
Instance details

Defined in GHC.Internal.Generics

Associated Types

type Rep1 (URec Char :: k -> Type)

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

type Rep1 (URec Char :: k -> Type) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UChar" 'PrefixI 'True) (S1 ('MetaSel ('Just "uChar#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UChar :: k -> Type)))

Methods

from1 :: forall (a :: k). URec Char a -> Rep1 (URec Char :: k -> Type) a #

to1 :: forall (a :: k). Rep1 (URec Char :: k -> Type) a -> URec Char a #

Eq1 (UChar :: Type -> Type) #

Since: base-4.21.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftEq :: (a -> b -> Bool) -> UChar a -> UChar b -> Bool #

Ord1 (UChar :: Type -> Type) #

Since: base-4.21.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftCompare :: (a -> b -> Ordering) -> UChar a -> UChar b -> Ordering #

Show1 (UChar :: Type -> Type) #

Since: base-4.21.0.0

Instance details

Defined in Data.Functor.Classes

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> UChar a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [UChar a] -> ShowS #

Foldable (UChar :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Foldable

Methods

fold :: Monoid m => UChar m -> m #

foldMap :: Monoid m => (a -> m) -> UChar a -> m #

foldMap' :: Monoid m => (a -> m) -> UChar a -> m #

foldr :: (a -> b -> b) -> b -> UChar a -> b #

foldr' :: (a -> b -> b) -> b -> UChar a -> b #

foldl :: (b -> a -> b) -> b -> UChar a -> b #

foldl' :: (b -> a -> b) -> b -> UChar a -> b #

foldr1 :: (a -> a -> a) -> UChar a -> a #

foldl1 :: (a -> a -> a) -> UChar a -> a #

toList :: UChar a -> [a] #

null :: UChar a -> Bool #

length :: UChar a -> Int #

elem :: Eq a => a -> UChar a -> Bool #

maximum :: Ord a => UChar a -> a #

minimum :: Ord a => UChar a -> a #

sum :: Num a => UChar a -> a #

product :: Num a => UChar a -> a #

Traversable (UChar :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> UChar a -> f (UChar b) #

sequenceA :: Applicative f => UChar (f a) -> f (UChar a) #

mapM :: Monad m => (a -> m b) -> UChar a -> m (UChar b) #

sequence :: Monad m => UChar (m a) -> m (UChar a) #

ToJExpr a => ToJExpr (Map String a) # 
Instance details

Defined in GHC.JS.Make

HasChar (Char, x) 
Instance details

Defined in GHC.Parser.String

Methods

getChar :: (Char, x) -> Char

setChar :: Char -> (Char, x) -> (Char, x)

Functor (URec Char :: Type -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

fmap :: (a -> b) -> URec Char a -> URec Char b #

(<$) :: a -> URec Char b -> URec Char a #

Generic (URec Char p) # 
Instance details

Defined in GHC.Internal.Generics

Associated Types

type Rep (URec Char p)

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

type Rep (URec Char p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UChar" 'PrefixI 'True) (S1 ('MetaSel ('Just "uChar#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UChar :: Type -> Type)))

Methods

from :: URec Char p -> Rep (URec Char p) x #

to :: Rep (URec Char p) x -> URec Char p #

Show (URec Char p) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

showsPrec :: Int -> URec Char p -> ShowS #

show :: URec Char p -> String #

showList :: [URec Char p] -> ShowS #

Eq (URec Char p) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

(==) :: URec Char p -> URec Char p -> Bool #

(/=) :: URec Char p -> URec Char p -> Bool #

Ord (URec Char p) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Methods

compare :: URec Char p -> URec Char p -> Ordering #

(<) :: URec Char p -> URec Char p -> Bool #

(<=) :: URec Char p -> URec Char p -> Bool #

(>) :: URec Char p -> URec Char p -> Bool #

(>=) :: URec Char p -> URec Char p -> Bool #

max :: URec Char p -> URec Char p -> URec Char p #

min :: URec Char p -> URec Char p -> URec Char p #

newtype Vector Char # 
Instance details

Defined in Data.Vector.Unboxed.Base

newtype Vector Char = V_Char (Vector Char)
data URec Char (p :: k) #

Used for marking occurrences of Char#

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

data URec Char (p :: k) = UChar {}
newtype MVector s Char # 
Instance details

Defined in Data.Vector.Unboxed.Base

newtype MVector s Char = MV_Char (MVector s Char)
type Compare (a :: Char) (b :: Char) # 
Instance details

Defined in GHC.Internal.Data.Type.Ord

type Compare (a :: Char) (b :: Char) = CmpChar a b
type Rep1 (URec Char :: k -> Type) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

type Rep1 (URec Char :: k -> Type) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UChar" 'PrefixI 'True) (S1 ('MetaSel ('Just "uChar#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UChar :: k -> Type)))
type Rep (URec Char p) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

type Rep (URec Char p) = D1 ('MetaData "URec" "GHC.Internal.Generics" "ghc-internal" 'False) (C1 ('MetaCons "UChar" 'PrefixI 'True) (S1 ('MetaSel ('Just "uChar#") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (UChar :: Type -> Type)))

ASCII Letters

isUpper :: Char -> Bool Source #

Detect upper case ASCII characters.

isUpper 'A' == True
isUpper 'B' == True
...
isUpper 'Z' == True
isUpper '0' == False
isUpper 'a' == False
isUpper '-' == False
isUpper 'Σ' == False

isLower :: Char -> Bool Source #

Detect lower case ASCII characters.

isLower 'a' == True
isLower 'b' == True
...
isLower 'z' == True
isLower '0' == False
isLower 'A' == False
isLower '-' == False
isLower 'π' == False

isAlpha :: Char -> Bool Source #

Detect upper case and lower case ASCII characters.

isAlpha 'a' == True
isAlpha 'b' == True
isAlpha 'E' == True
isAlpha 'Y' == True
isAlpha '0' == False
isAlpha '-' == False
isAlpha 'π' == False

isAlphaNum :: Char -> Bool Source #

Detect upper case and lower case ASCII characters.

isAlphaNum 'a' == True
isAlphaNum 'b' == True
isAlphaNum 'E' == True
isAlphaNum 'Y' == True
isAlphaNum '0' == True
isAlphaNum '7' == True
isAlphaNum '-' == False
isAlphaNum 'π' == False

Digits

isDigit :: Char -> Bool Source #

Detect digits 0123456789

isDigit '0' == True
isDigit '1' == True
...
isDigit '9' == True
isDigit 'a' == False
isDigit 'b' == False
isDigit 'A' == False

isOctDigit :: Char -> Bool Source #

Detect octal digits 01234567

isOctDigit '0' == True
isOctDigit '1' == True
...
isOctDigit '7' == True
isOctDigit '8' == False
isOctDigit 'a' == False
isOctDigit 'A' == False

isHexDigit :: Char -> Bool Source #

Detect hexadecimal digits 0123456789abcdefABCDEF

Conversion

toUpper :: Char -> Char Source #

Convert to upper case.

toLower :: Char -> Char Source #

Convert to lower case.

Unicode Code Points

toCode :: Char -> Int Source #

Convert to the corresponding Unicode code point.

toCode 'A' == 65
toCode 'B' == 66
toCode '木' == 26408
toCode '𝌆' == 0x1D306
toCode '😃' == 0x1F603

fromCode :: Int -> Char Source #

Convert a Unicode code point to a character.

fromCode 65      == 'A'
fromCode 66      == 'B'
fromCode 0x6728  == '\26408'  -- '木'
fromCode 0x1D306 == '\119558' -- '𝌆'
fromCode 0x1F603 == '\128515' -- '😃'
fromCode (-1)    == '\65533'  -- '�'

The full range of unicode is from 0 to 0x10FFFF. With numbers outside that range, you get the replacement character#Replacement_character).