Strong types for relational databases

Haskell's type system with multi-parameter constructor classes and functional dependencies allows static (compile-time) computations to be expressed by logic programming on the level of types. This emergent capability has been exploited for instance to model arbitrary-length tuples (heterogeneous lists), extensible records, functions with variable length argument lists, and (homogenous) lists of statically fixed length (vectors).We explain how type-level programming can be exploited to define a strongly-typed model of relational databases and operations on them. In particular, we present a strongly typed embedding of a significant subset of SQL in Haskell. In this model, meta-data is represented by type-level entities that guard the semantic correctness of database operations at compile time.Apart from the standard relational database operations, such as selection and join, we model functional dependencies (among table attributes), normal forms, and operations for database transformation. We show how functional dependency information can be represented at the type level, and can be transported through operations. This means that type inference statically computes functional dependencies on the result from those on the arguments.Our model shows that Haskell can be used to design and prototype typed languages for designing, programming, and transforming relational databases.

[1]  Chung-chieh Shan,et al.  Functional pearl: implicit configurations--or, type classes reflect the values of types , 2004, Haskell '04.

[2]  Ramez Elmasri,et al.  Fundamentals of Database Systems, 5th Edition , 2006 .

[3]  Ralf Lämmel,et al.  Strongly typed heterogeneous collections , 2004, Haskell '04.

[4]  Paulo Carreira,et al.  Efficient development of data migration transformations , 2004, SIGMOD '04.

[5]  Catriel Beeri,et al.  A complete axiomatization for functional and multivalued dependencies in database relations , 1977, SIGMOD '77.

[6]  Simon L. Peyton Jones Haskell 98 Libraries: Bibliography , 2003, J. Funct. Program..

[7]  Ralf Hinze Formatting: a class act , 2003, J. Funct. Program..

[8]  Peter Buneman,et al.  Type inference in a database programming language , 1988, LISP and Functional Programming.

[9]  David Maier,et al.  The Theory of Relational Databases , 1983 .

[10]  E. F. CODD,et al.  A relational model of data for large shared data banks , 1970, CACM.

[11]  Conor McBride Faking it: Simulating dependent types in Haskell , 2002, J. Funct. Program..

[12]  Ralf Lämmel,et al.  Haskell's overlooked object system , 2005, ArXiv.

[13]  Peter Buneman,et al.  Database programming in Machiavelli—a polymorphic language with static type inference , 1989, SIGMOD '89.

[14]  S. Elloumi,et al.  Discovering Regularities in Databases Using Canonical Decomposition of Binary Relations , 2004 .

[15]  Martin Andersson,et al.  Student paper: HaskellDB improved , 2004, Haskell '04.

[16]  Claudia Mónica Necco,et al.  Tower generic data processing , 2005 .

[17]  Peter Buneman,et al.  Polymorphism and type inference in database programming , 1996, TODS.

[18]  Jeffrey D. Ullman,et al.  Principles of Database and Knowledge-Base Systems, Volume II , 1988, Principles of computer science series.

[19]  José Nuno Oliveira,et al.  Type-Safe Two-Level Data Transformation , 2006, FM.

[20]  Daan Leijen,et al.  Domain specific embedded compilers , 1999, DSL '99.

[21]  C. J. Date An Introduction to Database Systems, 6th Edition , 1995 .

[22]  C. J. Date An introduction to database systems (7. ed.) , 1999 .

[23]  Ramez Elmasri,et al.  Fundamentals of Database Systems , 1989 .

[24]  Ramez Elmasri,et al.  Fundamentals of Database Systems, 2nd Edition , 1994 .