Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Data.Time.Calendar
import Control.Monad
import Data.List
data Person = P { p_id :: Int
, name :: String
, gender :: Int
, age :: Int
} deriving (Show, Eq)
data Group = G { g_id :: Int
, gname :: String
} deriving Show
data Assginment = A { a_id :: Int
, a_p_id :: Int
, a_g_id :: Int
, date :: Day
} deriving Show
persons = [ P 1 "Tarou" 1 10
, P 2 "Hanako" 2 20
, P 3 "Jirou" 1 30
, P 4 "Saburou" 1 40]
groups = [ G 1 "Matu", G 2 "Take", G 3 "Ume"]
assignments = [ A 1 1 1 (fromGregorian 2010 4 1)
, A 2 2 1 (fromGregorian 2009 9 1)
, A 3 3 2 (fromGregorian 2010 4 1)
, A 4 1 2 (fromGregorian 2010 5 1)]
main = print $ nub $ do
p <- persons
a <- assignments
guard (p_id p == a_p_id a &&
case toGregorian (date a) of
(y,_,_) -> y == 2010)
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment