r/ProgrammingLanguages • • Sep 01 '26

Discussion What is the interesting part of a programming language to you?

I've been working on some "documentation" for my own language (see here), which got me thinking: do we all see languages the same way? I personally look for unification of concepts and extensibility in a design, yet I've seen those who care deeply about functional purity or clean decompositions.
What do you look for in a programming language? And why?

36 Upvotes

111 comments sorted by

View all comments

Show parent comment

2

u/Potato871 Sep 02 '26

So for instance like Erlang's pattern matching compiler where invalid combinations just don't compile?

3

u/reflexive-polytope Sep 02 '26

For example, like OCaml's Map.Make (docs), where you can't break the data structure's invariants from external code.

Notice that the OCaml compiler doesn't verify the internal invariants. But, as long as Map.Make is implemented correctly, you don't need to check that third-party code might break these invariants.

2

u/Potato871 Sep 02 '26

This gives me the idea to implement a species of aliases for data structures which each guarantee some set of invariants through their exposed, and hidden, operations.

3

u/reflexive-polytope Sep 02 '26

I'd love to see how it eventually works.

2

u/Potato871 Sep 02 '26

Care to pitch me some basic set of invariants for a common type you'd want to see? I've not got anything better to do today because I'm meeting with my client tommorow and don't want to screw around with my higher level web code before then.

2

u/reflexive-polytope Sep 02 '26

In this code: https://github.com/eduardoleon/typhoon/blob/master/src/Graph.Strong.Gabow.sml

I want to statically express the fact that, in a graph with n nodes, the adjacency lists may only contain natural numbers < n.

It would spare me the safety check in line 31: if k >= 0 andalso k < size then.

But this isn't a problem you can solve in a single day. I've been trying for years, and even then, I only have bits and pieces of something vaguely solution-shaped.

1

u/Potato871 Sep 02 '26

Okay, here's my first crack at the problem:

bool expr_flag = false;
if(true) {
    Ptr int a; a.init(1,2,3);
    a.do(e => print("A: ",e));
    Ptr int b; b.init(0,1,12);
    b.do(e => print("B: ",e));


    b.validate_offests_and_lock(a);
    print("THIS SHOULD NOT PRINT");
    catch {
        expr_flag = true;
    }
}
print("Caught some exception while atetmpting to validate");
if(true) {
    Ptr int a; a.init(1,2,3,6);
    a.do(e => print("A_2: ",e));
    Ptr int b; b.init(0,1,2,3);
    b.do(e => print("B_2: ",e));


    b.validate_offests_and_lock(a);
    print("THIS SHOULD PRINT");
}


RESULT:


TEST START
A: 1
A: 2
A: 3
B: 0
B: 1
B: 12
ERROR: Element 2 of value 12 is out of bounds as an offset for column of length 3
5|1|0|G1522 TRAVEL_PASS Source at: 2|697|0|G10 Index: 6 
VAR_DECL a | Ptr_INIT a.init | Ptr_ITER_EXPR a.do | VAR_DECL b | Ptr_INIT b.init | Ptr_ITER_EXPR b.do | >Ptr_EXPR_A b.validate_offests_and_lock[IDENTIFIER b, IDENTIFIER validate_offests_and_lock] | print | catch | 
  Node: 3|500|0 Ptr_EXPR_A:DOT b.validate_offests_and_lock [C:2]{if}[Q: 3|667|0>DOT, 3|505|0>END] 
  Left: 3|483|0 Ptr_ITER_EXPR:DOT b.do [4|617|0](ptr[32] 2|735|2 u/12|28|0)[C:2]{if}[Q: 3|666|0>DOT, 3|498|0>END] 
  Root: 3|434|0 scope if [C:9][O:3|404|0|G37]{ROOT}[Q: 3|641|0>LBRACE, 3|521|0>RBRACE] 
ERROR IN TRAVEL_PASS ON LINE 8: Element 2 of value 12 is out of bounds as an offset for column of length 3
Caught some exception while atetmpting to validate
A_2: 1
A_2: 2
A_2: 3
A_2: 6
B_2: 0
B_2: 1
B_2: 2
B_2: 3
THIS SHOULD PRINT
TEST FINISHED

I haven't made it a specific type yet, I just added a 'become a validator' method to my universal data structure for the experiment. I also haven't yet implemented the locking aspect that would stop a or b from being mutated after it's been defined as a validator.
Thoughts?

2

u/reflexive-polytope Sep 02 '26

I can write a runtime validator in almost any existing language.

1

u/Potato871 Sep 02 '26

Well as I understand it the goal is to create a type who's invariant is that it contains indexes into a collection that are always in bounds, yes?
I'm trying to get the basic logic of 'validate these offsets' down, then, turn that into a type that can be passed and checked during compile time. Since I don't see a way to know the bounds of a dynamic container at compile time.

3

u/reflexive-polytope Sep 02 '26

In general, the answer is dependent types. However, crazy arbitrary dependent types turn programming into manual theorem proving, which is unpleasant.

Therefore, the challenge is to come up with a dependent type system that's just powerful enough to type array indexing, without sacrificing pleasant properties of a general-purpose language, like principal types and type inference.

→ More replies

1

u/Inconstant_Moo 🧿 Pipefish Sep 02 '26

It seems like you and u/reflexive-polytope might be talking about something like Pipefish's clone types.

Vec{i int} = clone list :
    len that == i

The escape hatch that u/polytope wants is an unsafe cast to the type. For example, we can define vector addition like:

(v Vec{i int}) + (w Vec{i int}) -> Vec{i} :
    unsafe Vec{i}, from a = [] for j::el = range v :
        a + [el + w[j]] 

The sum is assembled as an ordinary list, and then unsafely cast to Vec{i}, without checking its length.

1

u/reflexive-polytope Sep 02 '26

I never said anything about unsafe escape hatches.

Have a look at what I'm doing, if you want an idea of what my aims are.

1

u/Inconstant_Moo 🧿 Pipefish Sep 02 '26

You said "I want the ability to eagerly delimit a finite scope where this invariant can be potentially broken".

1

u/reflexive-polytope Sep 02 '26

Yes, but that doesn't require “unsafe escape hatches”. It requires modularity.

1

u/Inconstant_Moo 🧿 Pipefish Sep 03 '26

Well, maybe my way is more of a hatch and yours is more of a Grand Portal To The Escape Dimension, but it's still an escape from the usual rules, and I assume for the same reason, i.e. that you want that bit to be where you write the basic functions that you can make performant and check and test really thoroughly?

1

u/reflexive-polytope Sep 03 '26

Now I have no idea what you're going on about.

I wasn't talking about any “escape dimension”. I was talking about plain old abstract data types, a concept that's been well known and understood in computer science for decades.