# 定義 sum 型態

``````touchSensor :: Int -> Int
touchSensor 0 = ... -- 計算某值
touchSensor 1 = ... -- 計算某值
touchSensor 2 = ... -- 計算某值
touchSensor _ = ... -- 傳回一個值代表沒這個狀態
``````

``````data TouchSensor = Released | Pressed | Bumped
``````

``````touchSensor :: TouchSensor -> Int
touchSensor Released = ... -- 計算某值
touchSensor Pressed  = ... -- 計算某值
touchSensor Bumped   = ... -- 計算某值
``````

# 定義 product 型態

``````descCustomer :: (String, String, Int) -> String
descCustomer (firstName, lastName, age) =
"Customer(" ++ firstName ++ ", "
++ lastName  ++ ", "
++ show age  ++ ")"
``````

``````data Customer = Customer String String Int
``````

``````desc :: Customer -> String
desc (Customer firstName lastName age) =
"Customer(" ++ firstName ++ ", "
++ lastName  ++ ", "
++ show age  ++ ")"
``````

`Customer` 這樣的型態，它的值是由三個型態結合而成，又稱為 product 型態，而這也顯示了一個事實，在 Haskell 中，函式也會是型態定義之一，也就是說，值構造式也會是型態定義之一。

# 定義 sum 與 product 型態

``````data ColorSensor = Red Int | Yellow Int | Green Int
``````

``````data List = Empty | Con Int List
``````