Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Created Jul 15, 2017
Embed
What would you like to do?
-- data Person = Person String String Int Float String String deriving (Show)
-- レコード構文
-- ex.)
-- *Main> let guy = Person "Buddy" "Finklestein" 43 184.2 "526-2928" "Chocolate"
-- *Main> flavor guy
-- "Chocolate"
-- *Main> :t flavor
-- flavor :: Person -> String
data Person = Person {
firstName :: String,
lastName :: String,
age :: Int,
height :: Float,
phoneNumber :: String,
flavor :: String
} deriving (Show)
@mizukmb
Copy link
Author

mizukmb commented Jul 15, 2017

すごいHaskellたのしく学ぼう! 『第7章 型や型クラスを自分で作ろう』より

@mizukmb
Copy link
Author

mizukmb commented Jul 15, 2017

レコード構文でデータ型を定義すると Haskell がフィールド名の関数を作ってくれる。返す値はそこに突っ込んだ値。getterみたいな感じ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment