Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Gabe Schoenbach
  2.  
  3. module Records where
  4.  
  5.   -- Exercise 7.3
  6.   studentsOfTeacher_ :: [Person] -> Person -> [((Int, Int), [(String, String)])]
  7.   studentsOfTeacher_ students teacher
  8.     = [ (a, [(lastName b, firstName b)])
  9.       | a <- courses_teaching teacher
  10.       , b <- students
  11.       , (snd $ head $ courses_enrolled b) == a
  12.       ]
  13.      
  14.   studentsOfTeacher = studentsOfTeacher_ allStudents
  15.  
  16.   data Person
  17.     = Student
  18.         { firstName :: String
  19.         , lastName :: String
  20.         , id :: String
  21.         , major :: String
  22.         , year :: Int
  23.         , courses_enrolled :: [(String, (Int, Int))]
  24.         }
  25.     | Teacher
  26.         { firstName :: String
  27.         , lastName :: String
  28.         , dept :: String
  29.         , courses_teaching :: [(Int, Int)]
  30.         }
  31.  
  32.   professorChugh =
  33.     Teacher "Ravi" "Chugh" "CMSC" [(16100,1)]
  34.  
  35.   professorKurtz =
  36.     Teacher "Stuart" "Kurtz" "CMSC" [(16100,2), (28000,1)]
  37.  
  38.   allStudents =
  39.     [ Student "A" "Student" "********" "CMSC" 1 [("CMSC", (15100,1))]
  40.     , Student "B" "Student" "********" "CMSC" 1 [("CMSC", (16100,1))]
  41.     , Student "C" "Student" "********" "CMSC" 2 [("CMSC", (16100,2))]
  42.     , Student "D" "Student" "********" "MATH" 2 [("CMSC", (28000,1))]
  43.     , Student "E" "Student" "********" "MATH" 3 [("CMSC", (28000,1))]
  44.     , Student "F" "Student" "********" "ARTV" 3 [("CMSC", (12100,1))]
  45.     , Student "STEAM" "Student" "********" "ARTV" 4
  46.         [("CMSC", (16100,1)), ("ARTV", (22500,1)), ("ARTV", (22502,1))]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement