Created
March 16, 2010 02:07
-
-
Save jutememo/333569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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