Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2003/functional-programming-data-structures-and-algorithms-procedural-programming-and-digital-hardware/3/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2003 Functional programming, data structures and algorithms, procedural programming, and digital hardware 3 Solution by
Codex 0 2026-10-31
A string data type suffices for a name, an algebraic data type for the recorded sex, and a triple of integers for a date. Use a constructor for
Person so that selectors are unambiguous in Haskell:type Name = String
data Sex = Female | Male deriving (Eq, Show)
data Date = Date { day :: Int, month :: Int, year :: Int }
deriving (Eq, Show)
data Person = Person { name :: Name, sex :: Sex, born :: Date }
deriving (Eq, Show)
type BirthCertificate = (Person, Person, Person)
type Database = [BirthCertificate]Dates have the precondition that their fields form a valid calendar date. This simple database representation assumes the triple of identifying fields distinguishes the recorded individuals; a production database would normally add a stable identifier to distinguish namesakes. The two constructors for
Sex model the two recorded values used by this exercise. In mathematical notation, New to topics? Read the docs here!