Name: Anonymous 2018-10-12 17:08
So, why are you not using dependent types yet? Do you like your programs randomly crashing?
Vect n Int
while the head function requires a value of type Vect (n + 1) Int
C++ version with setters/getters on protected boxed value would work fine at runtimeThe issue is that the compiler will not warn you if you forget or mis-implement said getters/setters. See >>24
while the head function requires a value of type Vect (n + 1) IntIn that case dependent types are safer.
Would that also mean scanf equivalent function needs to implement handling dependent types as output?No
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
template<typename T,size_t size> class contain {private: T arr[size];
public:
T operator [](size_t i) const{
if(!(i<size)){puts("Requested Index out of range. Aborting");exit(2);}
return arr[i];};
T& operator[](size_t i) {
if(!(i<size)){puts("Input Index out of range. Aborting");exit(1);}
return arr[i];};};
int main(){
contain<int,50> A;
int i;
int rts=scanf("%d", &i);
A[i] = 100;
printf("%d", A[i]); return rts;}
Edited on 15/10/2018 04:53.
if it was so simple, we'd have done it by nowBut we have.
why would corporations who stand to lose a lot by getting hacked avoid something that would make them hack-proof?Because it is cheaper to hire Indians for pennies who have no idea about dependent types than hire people with some CS background. Why do you think that crap like Windows and Java are so popular?
B-b-but you can write code that output types!But I can also directly write that code without types as a middleman.
There’s no way you can encode all the logic to sanitize input in just types.What makes you think that? Haven't you heard of Curry–Howard isomorphism?
But I can also directly write that code without types as a middleman.Code that you can't prove that is correct, sure. This is why most programs nowadays are unstable and full of vulnerabilities.
https://www.exploit-db.com/All I see are bugs in software written in C and Java, neither of which have dependent types.
https://www.cvedetails.com/
which is not the caseWhat makes you think that in this specific case?
privilege escalation?Yes, dependent types protect against these.
overflows? numeric underflows?
null pointer dereferencing? uninitialized/improperly initialized memory?
format string vulnerabilities? array indexing errors? mismatched array new/delete? stack overrun? unused values?
remote code execution?
iterator invalidation of mutable data structures leading to undefined behavior?
unhandled return codes?
return pointers to local variables? invalid use of negative values?
underallocations of dynamic data?
file handle leaks?Pretty sure that you need linear types for these.
network resource leaks?
race conditions?
So, why are you not using dependent types yet? Do you like your programs randomly crashing?What if NPCs are incapable of writing safe code by design? They lack the level of abstract thought required to imagine the code being exploited. They just write code as requested by design and wonder why it randomly crashes and allows exploits.