Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Dependent types

Name: Anonymous 2018-10-12 17:08

So, why are you not using dependent types yet? Do you like your programs randomly crashing?

Name: Anonymous 2018-10-12 17:13

explain dependent types to someone who primarily uses java

Name: Snow Crash 2018-10-12 18:06

Use Internet Explorer to ask the AI Mind about dependent types:

http://ai.neocities.org/FirstWorkingAGI.html

Name: Anonymous 2018-10-12 18:08

Maybe because computers have a finite number of registers, accessible addressing space, and physical limitations, and a crash is what I need to determine something has gone wrong.

Name: Anonymous 2018-10-12 18:21

>>2
Thinking about or in terms of Java is painful.

>>3
Internet explorer does not work on Debian.

>>4
and a crash is what I need to determine something has gone wrong.
Dependent types help you find logical errors in your program, such as divisions by 0 and possible out of bounds accesses. Why would you need to wait until runtime in order to find a bug in your program? There are many released and supposedly stable programs in production that have passed testing and still have all kinds of bugs (including security bugs) that could have been prevented by dependent types.

Name: Anonymous 2018-10-12 18:24

>>5
if you can't explain it to someone who isn't familiar with it, you don't really understand it yourself

I didn't say you have to explain it in terms of java, just that I am not familiar with languages that use dependent types

Name: Anonymous 2018-10-12 18:32

>>6
The idea is basically that types may depend on values, so you can have something like List 50 Int for the type of a list with 50 elements. A functions like head that take the 1st element of a list could have a type like {t : Type} -> {length : t} -> (value : t) -> List (1 + length) t -> t
(the arguments in {} can automatically be deduced by the compiler)
And you get:
head (cons 9 nil) = 9
head nil = compile time type error as the type of nil is something like List 0 Int
That way you basically can't do things like int sussman[10]; sussman[90] = 100;

Name: Anonymous 2018-10-12 19:26

>>7
so it helps with array index out of bounds stuff, but can you give some specific real-world examples of when/where you'd use this?

how is this different from just exception handling where you make sure something isn't out of bounds?

Name: Anonymous 2018-10-12 20:01

>>8
so it helps with array index out of bounds stuff
Not only, you can even use it to avoid divisions by 0, as well as implement type-safe printfs. All kinds of things that have to do with safety and correctness really.

how is this different from just exception handling where you make sure something isn't out of bounds?
That this checks if your program is correct at compile time. You get an exception at runtime - possibly crashing your program.

Name: Anonymous 2018-10-12 20:13

Someone explain to me how the fuck you can check bounds purely at compile time. Let's say the array is user input. Yeah good luck buddy. You're still going to have a conditional branch in the machine code.

Name: Anonymous 2018-10-12 20:32

>>10
You're still going to have a conditional branch in the machine code.
Yes, did anyone tell you otherwise?
The point is that the compiler will tell you if you forget said conditional (due to the types not matching), dumbfuck.

Name: Anonymous 2018-10-12 20:35

>>11
Then why not use Python, Java, etc. which already do that but without the extra bookkeeping of types?

Name: Anonymous 2018-10-12 20:40

>>12
Except that they do not. None of these languages will warn you at compile time for such violations.

Name: Anonymous 2018-10-13 0:50

Name: Anonymous 2018-10-13 3:02

>>7
The idea is basically that types may depend on values, so you can have something like List 50 Int for the type of a list with 50 elements.
Then C got dependent types:
typedef int dependent_type[50];
dependent_type A;
That way you basically can't do things like int sussman[10]; sussman[90] = 100;

gcc -Wall -pipe -O3 dep.c
typedef int dependent_type[50];
dependent_type A;
#include <stdio.h>
int main(){A[90]=100;printf("%d",A[90]);;}

dep.c: In function ‘int main()’:
dep.c:4:16: warning: array subscript is above array bounds [-Warray-bounds]
int main(){A[90]=100;printf("%d",A[90]);;}

Name: Anonymous 2018-10-13 3:11

>>15
-Werror -Wfatal-errors will halt compilation on any errors/warnings
gcc -Wall -Werror -Wfatal-errors -pipe -O3 dep.c

dep.c: In function ‘int main()’:
dep.c:4:16: error: array subscript is above array bounds [-Werror=array-bounds]
int main(){A[90]=100;printf("%d",A[90]);;}
^
compilation terminated due to -Wfatal-errors.
cc1plus: all warnings being treated as errors

Name: Anonymous 2018-10-13 15:52

>>15
int main(){A[90]=100;printf("%d",A[90]);;}
Now try
int main(){int i; scanf("%d\n", &i); A[i] = 100; printf("%d\n", i);}
It will compile just fine.

Name: Anonymous 2018-10-13 15:53

*printf("%d\n", A[i]);

Name: Anonymous 2018-10-13 15:58

Name: Anonymous 2018-10-13 18:44

>>19
Type safe division: https://gist.github.com/edwinb/0047a2aff46a0f49c881
I can just catch ZeroDivisionError in other langs to achieve the same exact thing.

Name: Anonymous 2018-10-13 18:58

>>20
the same exact thing
"Data loss" and "crashing on runtime" is not the exact same effect as "catching a possible error at compile time".

Name: Anonymous 2018-10-13 20:30

marathon = runtime
bukkake = cum pile time

Name: Anonymous 2018-10-13 22:48

>>21
all the Idris code does is force you to check if the divisor is 0, as if all division procedures in other languages don't already check if the divisor is zero. instead of crashing, in Idris you have, print "Attempt to divide by zero!", which is literally no different than catching the exception and doing that.

tl;dr the emperor has no clothes

Name: Anonymous 2018-10-13 23:08

>>23
instead of crashing, in Idris you have, print "Attempt to divide by zero!"
You have to use choose only on user input. For non-user input you might not need to do that (so you will not need to have any print "Attempt to divide by zero!").

which is literally no different than catching the exception and doing that
Except that you might forget to catch said exception. "b-buuut the compiler will warn me!" - what if you pass a provably non-zero divisor? You will have to still catch the exception, which is retarded.
Also, try to think of it from another way: what if you are dividing by a value that you think that will never be 0 but in reality it might be 0? You will simply not get any compile time warning that you fucked up in languages with non-dependent types.

Name: Anonymous 2018-10-14 5:02

>>17
A C program will probably include a runtime check to avoid that. Like if(index >= sizeof(array)){deny}

Name: Anonymous 2018-10-14 8:05

>>25
"Probably" - except if it is one of the many programs that do not, or have an incorrect one (such as heart-bleed or such as your very own example - I think you mean sizeof array / sizeof *array instead - which does not work correctly for pointers), along with no warning if one is incorrect or missing.

Name: Anonymous 2018-10-14 8:13

>>26
This can be predefined
const int MAX_INDEX_OF_F=20;
#define MAX_INDEX_OF_F 20
if(index >=MAX_INDEX_OF_F)

Name: Anonymous 2018-10-14 8:16

Sure, but it just shows how easy it is to fuck up - something that languages with dependent types stop for free.

Name: Anonymous 2018-10-14 9:48

>>28
for free
Thats a lie. Garbage collection, performance, long compile times and complexity of implementation.

Name: Anonymous 2018-10-14 13:33

>>29
Garbage collection
Not more necessary than any language.

performance
Type checking happens only at compile time, in fact it has the opportunity of being faster since you do not need to check if your arguments are null everywhere.

long compile times
Faster than C++. And it's not like compile times really matter, you are not going to recompile the whole project every time you make a change - only the file(s) that you changed.

complexity of implementation
I have implemented a dependent type system in 100 lines of code. Pretty sure that this is less than even the type system of the average C implementation or haskell.

Name: Anonymous 2018-10-14 13:51

Proof for how easy it is to implement it: https://www.andres-loeh.de/LambdaPi/LambdaPi.pdf

Name: Anonymous 2018-10-14 13:55

>>30
I have implemented a dependent type system in 100 lines of code.
Extraordinary claims require extraordinary evidence.

Name: Anonymous 2018-10-14 14:10

>>32
See >>31

Name: Anonymous 2018-10-14 14:14

>>33
Thats not code, its a theoretical paper and much larger than 100 lines.

Name: Anonymous 2018-10-14 14:14

CoC's inference rules, you must be a mental midget to need more than 100 lines of code to implement them https://en.wikipedia.org/wiki/Calculus_of_constructions#Inference_rules_for_the_calculus_of_constructions

Name: Anonymous 2018-10-14 14:21

>>34
It is not a theoretical paper, it is a practical tutorial.

Name: Anonymous 2018-10-14 14:21

>>35
Burden of proof is on you, you claim that "I have implemented a dependent type system in 100 lines of code." Sophistry about mental midgets is irrelevant.

Name: Anonymous 2018-10-14 14:22

>>36
shows paper clearly lacking code and clearly not written by him
"I have implemented a dependent type system in 100 lines of code."
where it is
"Its...in the paper..somewhere.."

Name: Anonymous 2018-10-14 14:28

>>38
Whom art thou quoting?
I never said that I will post my implementation.
Apparently though you are too stupid to look for one by yourself https://gist.github.com/ChristopherKing42/d8c9fde0869ec5c8feae71714e069214

Name: Anonymous 2018-10-14 14:46

>>39
So its essentially:
1.A fairly normal C++ Class Template
2.The setter function filters incoming values by an internal parameter(such as size or something).
3.A getter function throws exception(Nothing) if something outside of range is requested.
What is so revolutionary about this?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List