|
|
|
|
|
by combatentropy
3337 days ago
|
|
> Dependent types
>
> Example languages: Idris, Agda, Coq
>
> You’re probably used to type systems in languages like C and Java,
> where the compiler can check that a variable is an integer, list, or string.
> But what if your compiler could check that a variable is “a positive integer”,
> “a list of length 2”, or “a string that is a palindrome”?
This is what I love about SQL. You can even define your own types, like "email", at least in PostgreSQL: create table contacts (
name text not null,
age int check (age >= 0),
email email
);
It already has a few of these special types built in, like for IP and MAC addresses (https://www.postgresql.org/docs/current/static/datatype.html). |
|
Thus, a dependently typed database would allow one columns type to depend on the value of another column.
It would be like saying
Notice the 'if' in the type of fieldValue