3 ms·
> That is, as an example in our case, we can’t expect that a Haskell data type that today maps perfectly to a SQL row will continue to do so after any of the tw
by i_s 11y ago
> That is, as an example in our case, we can’t expect that a Haskell data type that today maps perfectly to a SQL row will continue to do so after any of the two is modified.
But we can and do if we use the compiler to dynamically generate code. For example, with F#'s SqlClient (a type provider) [0], types are generated based on queries, correctly mapping database columns (including nullable ones) to fields on types. If you change the queries, or tables (and you are doing 'select *'), the types get updated automatically. This seems like a better approach.
This is also similar to how popular popular db access approaches in dynamic languages such as ActiveRecord in RoR work. Tables are inspected at runtime, and getters, setters and utility methods are generated based on that.
I imagine this is also possible in Haskell via Template Haskell, which the author dismisses as too complex/fragile, though I don't know Haskell well enough to be sure.
[0] - http://fsprojects.github.io/FSharp.Data.SqlClient/ http://fsprojects.github.io/FSharp.Data.SqlClient/
- thesz 11y agoDo type providers provide you with semantics difference when type errors occur? If not (e.g. they don't tell you about arity mismatch citing relevant part of awl query), then they are inferior to the method of expression of queries in type level.