Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created March 16, 2010 02:07
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 jutememo/333569 to your computer and use it in GitHub Desktop.
Save jutememo/333569 to your computer and use it in GitHub Desktop.
import Control.Monad.State
-- 人
data Person = Person { name :: String -- 名前
, age :: Int -- 年齢
} deriving Show
-- グループ
data Group = Group [Person] deriving Show
g = Group []
-- グループに人を追加
addPerson :: Person -> Group -> ((), Group)
addPerson p (Group ps) = ((), Group (ps++[p]))
addPs' (n,a) = State $ addPerson $ Person n a
addPs1 = mapM_ addPs' [("Tarou",10), ("Jirou",20), ("Hanko",30)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment