갈루아의 반서재

하스켈의 Data.Char 모듈에는 문자를 다루는 다수의 함수가 포함되어 있다. 

먼저 :m Data.Char 과 같이 해당 모듈을 로딩한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Prelude> :m Data.Char
 
Prelude Data.Char> isLower 'b'
True
it :: Bool
 
Prelude Data.Char> toUpper 'a'
'A'
it :: Char
 
Prelude Data.Char> ord 'A'
65
it :: Int
 
Prelude Data.Char> chr 66
'B'
it :: Char
cs

아래와 같이 모듈명을 붙여서(with a qualified name) 참조할 수도 있다.

1
2
3
Prelude> Data.Char.ord 'G'
71
it :: Int
cs

함수의 타입을 알아보기 위해 gchi 의 :type 명령어를 사용할 수 있다.

1
2
Prelude> :type isLower
isLower :: Char -> Bool
cs

여기서 -> 는 as "to" 라고 읽는다.

Char -> Bool 이 의미하는 것은 해당 함수는 문자 타입의 인수를 받아서 불 타입으로 그 결과를 반환한다는 것이다. 위에서 사용된 함수의 타입을 좀 더 살펴보자.

1
2
3
4
5
6
7
8
Prelude Data.Char> :type toUpper
toUpper :: Char -> Char
 
Prelude Data.Char> :type ord
ord :: Char -> Int
 
Prelude Data.Char> :type chr
chr :: Int -> Char
cs

:browse Data.Char 와 같이 해당 모듈에 속한 모든 함수의 타입을 한 번에 살펴볼 수도 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Prelude> :browse Data.Char
data Data.Char.GeneralCategory
  = Data.Char.UppercaseLetter
  | Data.Char.LowercaseLetter
  | Data.Char.TitlecaseLetter
  | Data.Char.ModifierLetter
  | Data.Char.OtherLetter
  | Data.Char.NonSpacingMark
  | Data.Char.SpacingCombiningMark
  | Data.Char.EnclosingMark
  | Data.Char.DecimalNumber
  | Data.Char.LetterNumber
  | Data.Char.OtherNumber
  | Data.Char.ConnectorPunctuation
  | Data.Char.DashPunctuation
  | Data.Char.OpenPunctuation
  | Data.Char.ClosePunctuation
  | Data.Char.InitialQuote
  | Data.Char.FinalQuote
  | Data.Char.OtherPunctuation
  | Data.Char.MathSymbol
  | Data.Char.CurrencySymbol
  | Data.Char.ModifierSymbol
  | Data.Char.OtherSymbol
  | Data.Char.Space
  | Data.Char.LineSeparator
  | Data.Char.ParagraphSeparator
  | Data.Char.Control
  | Data.Char.Format
  | Data.Char.Surrogate
  | Data.Char.PrivateUse
  | Data.Char.NotAssigned
Data.Char.digitToInt :: Char -> Int
Data.Char.generalCategory :: Char -> Data.Char.GeneralCategory
Data.Char.isLetter :: Char -> Bool
Data.Char.isMark :: Char -> Bool
Data.Char.isNumber :: Char -> Bool
Data.Char.isPunctuation :: Char -> Bool
Data.Char.isSeparator :: Char -> Bool
Data.Char.isSymbol :: Char -> Bool
data Char = GHC.Types.C# GHC.Prim.Char#
GHC.Char.chr :: Int -> Char
GHC.Show.intToDigit :: Int -> Char
GHC.Unicode.isAlpha :: Char -> Bool
GHC.Unicode.isAlphaNum :: Char -> Bool
GHC.Unicode.isAscii :: Char -> Bool
GHC.Unicode.isAsciiLower :: Char -> Bool
GHC.Unicode.isAsciiUpper :: Char -> Bool
GHC.Unicode.isControl :: Char -> Bool
GHC.Unicode.isDigit :: Char -> Bool
GHC.Unicode.isHexDigit :: Char -> Bool
GHC.Unicode.isLatin1 :: Char -> Bool
GHC.Unicode.isLower :: Char -> Bool
GHC.Unicode.isOctDigit :: Char -> Bool
GHC.Unicode.isPrint :: Char -> Bool
GHC.Unicode.isSpace :: Char -> Bool
GHC.Unicode.isUpper :: Char -> Bool
GHC.Read.lexLitChar :: ReadS String
GHC.Base.ord :: Char -> Int
GHC.Read.readLitChar :: ReadS Char
GHC.Show.showLitChar :: Char -> ShowS
GHC.Unicode.toLower :: Char -> Char
GHC.Unicode.toTitle :: Char -> Char
GHC.Unicode.toUpper :: Char -> Char
Prelude>
 
cs