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
-- グループに人を追加
addPerson :: Person -> Group -> ((), Group)
addPerson p (Group ps) = ((), Group (ps++[p]))
addPs' (n,a) = State $ addPerson $ Person n a
toTuple :: String -> (String, Int)
toTuple cs = read line where line = '(' : cs ++ ")"
g = Group []
main = do cs <- getContents
print $ (execState $ mapM_ addPs' $ map toTuple $ lines cs) g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment