Skip to content

Instantly share code, notes, and snippets.

@mizukmb
Created July 15, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizukmb/7457f048bf9b89f384db034c90e7795f to your computer and use it in GitHub Desktop.
Save mizukmb/7457f048bf9b89f384db034c90e7795f to your computer and use it in GitHub Desktop.
-- 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 がフィールド名の関数を作ってくれる。返す値はそこに突っ込んだ値。getterみたいな感じ

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