2. Int

`Int`是代表`Integer`型別資料的型別類。`2147483647``-2147483647`範圍內的每個整數都屬於`Int`型別類。在下面的範例中，函式`fType()`將根據定義的型別來表示。

``````fType :: Int -> Int -> Int
fType x y = x*x + y*y
main = print (fType 2 4)
``````

``````sh-4.3\$ ghc -O2 --make *.hs -o main -threaded -rtsopts
sh-4.3\$ main
20
``````

3. Integer

`Integer`可以視為`Int`的超集。此值不受任何數位限制，因此`Integer`可以是任何長度，沒有任何限制。要了解`Int``Integer`型別之間的基本區別，修改上面的程式碼如下所示：

``````fType :: Int -> Int -> Int
fType x y = x*x + y*y
main = print (fType 212124454 44545454454554545445454544545)
``````

``````main.hs:3:31: Warning:
Literal 44545454454554545445454544545 is out of the Int range -
9223372036854775808..9223372036854775807
``````

``````fType :: Integer -> Integer -> Integer
fType x y = x*x + y*y
main = print (fType 212124454 4454545445455454545445445454544545)
``````

``````sh-4.3\$ main
1984297512562793395882644631364297686099210302577374055141
``````

4. Float

``````
fType :: Float -> Float -> Float
fType x y = x*x + y*y
main = print (fType 2.5 3.8)
``````

``````sh-4.3\$ main
20.689999
``````

5. Double

`Double`是浮點數，它的末尾具有雙精度。看下面的範例程式碼：

``````fType :: Double -> Double -> Double
fType x y = x*x + y*y
main = print (fType 2.56 3.81)
``````

``````sh-4.3\$ main
21.0697
``````

6. Bool

Bool是布林型別。它的值可以是`True``False`。執行以下程式碼以了解`Bool`型別在Haskell中的工作方式。

``````main = do
let x = True

if x == False
then putStrLn "X matches with Bool Type"
else putStrLn "X is not a Bool Type"
``````

``````sh-4.3\$ main
X is not a Bool Type
``````

7. Char

`Char`代表字元。單引號內的所有內容均視為字元。在下面的程式碼中，我們修改了前面的`fType()`函式以接受`Char`值並將`Char`值返回為輸出。

``````fType :: Char-> Char
fType x = 'K'
main = do
let x = 'v'
print (fType x)
``````

``````sh-4.3\$ main
'K'
``````

8. EQ型別類

EQ型別類是提供測試表示式是否相等的功能的介面。檢查表示式是否相等的型別類都應屬於此EQ型別類。

``````main = do
if 8 /= 8
then putStrLn "The values are Equal"
else putStrLn "The values are not Equal"
``````

``````sh-4.3\$ main
The values are not Equal
``````

9. Ord型別類

Ord是另一個提供排序功能的介面類。到目前為止，使用的所有型別都是`Ord`介面的一部分。與EQ介面類似，可以使用`>``<``<=``>=``compare`來呼叫Ord介面。

``````main = print (4 <= 2)
``````

``````sh-4.3\$ main
False
``````

10. Show

`Show`具有將引數列印為字串的功能。無論引數是什麼，它始終將結果列印為字串。在以下範例中，我們將使用此介面列印整個列表。`Show`可用於呼叫此介面。

``````main = print (show [1..10])
``````

``````sh-4.3\$ main
"[1,2,3,4,5,6,7,8,9,10]"
``````

`Read`介面的功能與顯示相同，但不會以字串格式列印結果。在以下程式碼中，使用`read`介面讀取字串值並轉換為`Int`值。

``````main = print (readInt "12")
readInt :: String -> Int
``````

``````sh-4.3\$ main
12
``````

12. Enum

``````main = print (succ 12)
``````

``````sh-4.3\$ main
13
``````

13. Bounded

``````main = do
print (maxBound :: Int)
print (minBound :: Int)
``````

``````sh-4.3\$ main
9223372036854775807
-9223372036854775808
``````

14. Num

`Num`型別類用於數位運算。諸如`Int``Integer``Float``Double`之類的型別都屬於此`Type`類。看一下下面的程式碼-

``````main = do
print(2 :: Int)
print(2 :: Float)
``````

``````sh-4.3\$ main
2
2.0
``````

16. Floating

`Integral`一樣，`Floating`也是`Num Type`類的一部分，但它僅包含浮點數。因此，`Float``Double`屬於此類型別。

17. 自定義Type類

``````data Area = Circle Float Float Float
surface :: Area -> Float
surface (Circle _ _ r) = pi * r ^ 2
main = print (surface \$ Circle 10 20 10 )
``````

``````sh-4.3\$ main
314.15927
``````