``````data Rectangle = Rect Int Int Int Int deriving Show
``````

``````xOf (Rect x _ _ _) = x
yOf (Rect _ y _ _) = y
widthOf (Rect _ _ w _) = w
heightOf (Rect _ _ _ h) = h
``````

# 使用 Record 記錄各項名稱

``````data Rectangle = Rect { x :: Int
, y :: Int
, width :: Int
, height :: Int } deriving Show
``````

# 建立 Type 同義詞

``````import Data.Char

allToUpper :: [[Char]] -> [[Char]]
allToUpper xs = [map toUpper x | x <- xs]
``````

``````import Data.Char

allToUpper :: [String] -> [String]
allToUpper xs = [map toUpper x | x <- xs]
``````

``````type String = [Char]
``````

``````type UrlMappingLt = [([Char], [Char])]
``````

# 具型態參數的同義詞

``````data Map k v = Empty | Cm (k, v) (Map k v)

fromList :: [(k, v)] -> Map k v
fromList [] = Empty
fromList (x:xs) = Cm x (fromList xs)

findValue :: (Eq k) => k -> Map k v -> Maybe v
findValue key Empty = Nothing
findValue key (Cm (k, v) xm) =
if key == k then Just v else findValue key xm
``````

``````type PairLt k v = [(k, v)]
``````

``````fromList :: PairLt k v -> Map k v
fromList [] = Empty
fromList (x:xs) = Cm x (fromList xs)
``````

``````lookUpByName :: [Char] -> [([Char], v)] -> Maybe v
lookUpByName n ((name, value):xs) =
if n == name then Just value else lookUpByName n xs
``````

``````type StringKeyPairLt v = [([Char], v)]

lookUpByName :: String -> StringKeyPairLt v -> Maybe v
lookUpByName n ((name, value):xs) =
if n == name then Just value else lookUpByName n xs
``````