From 8250705ecb182f9ea0da4b4dacd79350eee68791 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 8 Mar 2016 11:59:55 -0500 Subject: [PATCH] [icfp] note: typed/racket db imports --- icfp-2016/implementation.scrbl | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/icfp-2016/implementation.scrbl b/icfp-2016/implementation.scrbl index f8b7683..ddd781e 100644 --- a/icfp-2016/implementation.scrbl +++ b/icfp-2016/implementation.scrbl @@ -15,6 +15,46 @@ +@section{Database} + +Note: Typed Racket users can already specialize functions from the @tt{db} library + by giving them exact types in an import statement: + +@racketblock[ + (require/typed db + (#:opaque Connection connection?) + (postgresql-connect (->* () (#:user String #:database String) Connection)) + (query-row (-> Connection String Any * (Vector Natural String))) + (query-maybe-row (-> Connection String Any * (Option (Vector Natural String)))) + ....) +] + +The above statement asserts that @racket[query-row] only returns rows containing + a natural number followed by a string. +To work with multiple tables in the same module, a programmer can re-import + @racket[db] functions using a different name and type. + +@todo{cohernet table names} +@racketblock[ + (require/typed (prefix-in w: db) + (w:query-row (-> Connection String Any * (Vector Natural String)))) + + (require/typed (prefix-in s: db) + (s:query-row (-> Connection String Any * (Vector Natural Natural)))) +] + +@todo{Other languages? also follow this approach} + +The benefits of our approach are: +@itemlist[ + @item{ + Single point of control for database types, instead of spreading types + across identifiers in the @racket[require/typed] statement. + } + @item{ + Compile-time validation of query strings. + } +]