Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Data.Maybe
data Person = Person { name :: String
, partner :: Partner
} deriving Eq
-- パートナー
type Partner = Maybe Person
instance Show Person where
show (Person n Nothing) = n
show (Person n p) = n ++ "{" ++ (name $ fromJust p) ++ "}"
-- 誕生
born n = Person n Nothing
-- 結婚
marry p1 p2 = (p1 { partner = Just p2 }, p2 { partner = Just p1 })
-- 離婚
divorce (p1,p2) = (p1 { partner = Nothing }, p2 { partner = Nothing })
main = do let tarou = born "Tarou"
hanako = born "Hanako"
m = marry tarou hanako
d = divorce m
print m -- (Tarou{Hanako},Hanako{Tarou})
print d -- (Tarou,Hanako)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment