Real World Haskell - 第3章 Part5 Record syntax

Real World HaskellHaskell を継続的に勉強中。

Defining Types, Streamlining Functions

Chapter 3. Defining Types, Streamlining Functions

Record syntax
  • data type の components への accessors は、record syntax で簡単に書ける
data Customer = Customer {
      customerID      :: CustomerID
    , customerName    :: String
    , customerAddress :: Address
    } deriving (Show)
ghci> customer1
Customer {customerID = 271828, customerName = "J.R. Hacker", customerAddress = [ (truncated)
ghci> :type customerName
customerName :: Customer -> String
ghci> customerName customer1
"J.R. Hacker"

参考

Haskell Language
Haskell - Wikipedia

Haskellハスケル)は非正格な動作を持つ純粋関数型プログラミング言語である。名称は論理学者であるハスケル・カリー(Haskell B. Curry)に由来する。