Some Thoughts on Programming Language Design

This is a collection of ideas to look at when inventing new langauges.

Other Ideas

Type System

# Haskell
data LinkedList a = Nil | Cons a (Box (LinkedList a))
data Test = Empty | Blub Int | State { x :: Int, y :: Int }
# Rust
enum LinkedList { Nil, Cons(T, LinkedList) }

Memory Management

Compile-time logic

fn format(template: String, args: [String]) -> String {
    template.replace("@", (match, i) => args[i])
}

fun add(x, y) x + y

fun main() print(format!("@ ist @; @", ["1+1", 1+1, x]))
# should expand to
fun main() print("1+1 ist 2; " ~ x))

Examples

Fizz-Buzz

for (n in 0..100) {
    if (n % (3*5) == 0) print("FizzBuzz")
    else if (n % 3 == 0) print("Fizz")
    else if (n % 5 == 0) print("Buzz")
    else print(n)
}


if (true) x = 1
if (true) { x = 1 }
f(x) = 10 + g(x)
f x = 10 + g x

main = {

}

changes to this article (as recorded with git; visible on codeberg)

2023-01-08 77eef59 more ideas
2022-11-10 0bef88a include new features