A programming language back from the future¶

UNISON

sdsd

Agenda¶

sdsd

  • Introduction to "unison the programming language"

  • Introduction of the domain problem

  • Introduction to "unison the not programming language"

Introduction to "unison the programming language"

sdsd

The basis¶

  • We will work on a single file names scratch.u

  • On the side of scratch.u we will start ucm (Unison Codebase Manager) in a terminal.

  • Each time we save scratch.u, ucm will take the change and run & print each statement after a >

Hello World¶

-- scratch.u
msg = "Hello World"
> msg
  1. msg is a constant
  2. the usage of > is kind of a print
  3. the ucm kind of a repl

First function¶

-- scratch.u
Add1 x = x + 1
> Add1 32
  1. Unison is an "haskell like" language
  2. functions are defined in the most direct way
  3. Calling a function does not requires parenthisis

Second function¶

-- scratch.u
Add1 x = x + 1
Times2 x = x * 2
Add1Times2 x = Times2 (Add1 x)

> Add1Times2 5
  1. Still no parenthisis to define the arguments
  2. Parenthisis are only use to show priority ( Times2 (Add1 x) is not the same as Times2 Add1 x)

Turing completeness¶

-- scratch.u
fibb x = if x < 1 then 1 else ((fibb (x - 1)) + (fibb (x - 2)))

> fibb 6
  1. There is an if-then-else primitive...
  2. Loops are made with recursion

Types¶

-- scratch.u

structural type LinkList t = Nil | Cons t (LinkList t)

ll = Cons 2 (Cons 1 (Cons 0 Nil))

> ll
  1. Unison is a very strongly typed language
  2. The above code is the "classical" example of a linked list 3 Indeed, it uses generics types

For the geeks of the geeks¶

  • Unison is a purely functional strongly typed programming language

  • Unison is greedy (aka, not lazy)

  • Unison uses "algebraic effects" to handle side effects

  • Unison runtime is Chez Scheme (or soon will be)

For the rest of the presentation...¶

-- scratch.u
Add1 x = x + 1
Times2 x = x * 2
Add1Times2 x = Times2 (Add1 x)

> Add1Times2 5
  1. We need to focus on the essential
  2. We are going to use dull mathematical functions

Introduction of the domain problem¶

sdsd

Q&A question...¶

  • Hey kids, when you program, what do you do with important data?

You put that data in a database!

  • Hey kids, when you program, what is your most important data?

Your source code

  • Hey kids, why your source code is not in a database?

Because we still code in a "pre-database era" fashion

But Git is a code database¶

  • Not really, Git has not idea of your source code

  • Git tracks files, nothing else

  • The source code is still in files

  • Saying your source code is in a database because it is versionned in Git is like saying your json blobs are in a database because they are stored as VARCHAR in mysql.

  • Git a absolutly amazing (best software ever written?)

unison is a programming language..

  1. That puts your source code in a database

  2. The rest we do not care

unison the not programming language

sdsd

We will add one function to our database¶

In the scratch.u¶

Add1 x = x + 1

> Add1 5

In the ucm¶

# ucm
add

We will add a second function to our database¶

In the scratch.u¶

Add2 x = Add1 (Add1 x)

> Add2 5

In the ucm¶

# ucm
add

We will add a third function to our database¶

In the scratch.u¶

Add3 x = Add1 (Add1 (Add1 x))

> Add3 5

In the ucm¶

# ucm
add

List the functions that we have in the database¶

In the ucm¶

# ucm
ls

Look at a function¶

In the ucm¶

# ucm
view Add2

Note¶

  • the function has been magically linted

Look at all the dependecies of a function¶

In the ucm¶

dependencies Add3

Look at all the dependents of a function¶

In the ucm¶

dependents Add1

unison the Genious Idea

sdsd

Content-addressable storage¶

is a way to store information so it can be retrieved based on its content, not its name or location.

-- wikipedia

Content-addressable storage¶

We have a table that store "things". The primary key of the table is the "hash" of the "things".

Id Text
ff5b5776505060eec58fff6f462a8fe9 "didier"
da8dee114a147c07ef0527ac3a6e1d58 "maxime"
3258460251858f7db401b0b70af6b925 "ivo"
201b00ab3b5fba10c15a4e5b8695c478 "mohit"
4794571aa96694574177576ba90ef3bb "faiz"

Important¶

  • it is impossible to find two values with the same hash
  • the only way to know the id, is to know the value
  • Make things "immutable"

Content-addressable storage is used in multiple "good" software¶

  • git (git commit are content addressable)

  • bitcoins

  • public key infrastructure, public keys are associated with their hash

  • bit torrent

  • nix

How does unison uses Content-addressable storage ?

  • Unison only stores the "abstract syntax tree" (not the text of the source code)

  • Unison hashes the "abstract syntax tree" as primary key

  • Functions are named by their hashes

  • Visible function names are only "labels"

How does unison uses Content-addressable storage ?

Source Table
HashSource
t7g50rohbm
x -> x + 1
qkrj8bbq2m
x -> t7g50rohbm (t7g50rohbm X)
Labels
LabelHash
t7g50rohbm
Add1
qkrj8bbq2m
Add2

How does unison uses Content-addressable storage ?

  • We can consider the "hash" of a function as its cannonical name

How the hash works?¶

The code¶

Add1 x = x + 1

The abstract syntaxt tree¶

sdsd

How the hash works? (continuation...)¶

Arguments anonymization¶

sdsd

How the hash works? (continuation...)¶

Normalization of function names¶

sdsd

How the hash works? (continuation...)¶

And then we hash all that!¶

The hash of `x -> x + 1` is `t7g50rohbm`

For Java programmers, it could look like something such as¶

List.of(
    "function",
    List.of(
        "arguments", List.of("argument_1")),
    List.of("body", List.of("#65ba56", "argument_1", "1"))).hashCode()

Terminology | Merkle tree¶

Merkle tree is a tree in which every "leaf" node is labelled with the cryptographic hash of a data block

-- wikipedia

sdsd

Advantages of this approach¶

  1. Functions are immutable; it is impossible to rename a function
  2. It is impossible to "break" a function; all functions are built-in the functions
  3. Compiler needs to compile each function exactly once
  4. Tooling can be amazing!

unison the merkel tree

sdsd

Listing all the names of a function..¶

List all names for Add1¶

#ucm
names Add1

Add a function with the same code as Add1¶

-- scratch.u
AddOne x = x + 1
#ucm
add

List all names for Add1¶

#ucm
names Add1

Renaming function¶

ucm
rename Add1 Add_1

Delete function¶

ucm
delete Add1 

Updating function¶

Get help from ucm to edit the function¶

#ucm
edit AddTwo

Update the function in text file¶

-- scratch.u
AddTwo x = x + 2

Update the function in the db¶

#ucm
update

Insanely cool documentation¶

Write documentaion¶

-- scratch.u
AddOne.doc = {{ 
Adds one to the input number.

    ```
    AddOne 10
    ```
}}

Add documentaion to the db¶

#ucm
add

View documentaion in web browser¶

#ucm
ui

Inside the database?¶

We can look inside unison's database by connecting to the sqlite3 database located at $HOME/.unison/v2/unison.sqlite3

Conclusion¶

sdsd

About unison¶

  • Unison is at the very top of "cool new things about programming language"

  • Unfortunatly, it is hard to start small while using unison

  • It would be cool if other programming environment could use a similar approach (java?, javascript?)

About Content-addressable storage¶

  • We should always use content-addressable storage when possible

  • content-addressable storage is not harder to use and simplify implementation of ass kicking features

Other cool technology we could look at¶

  • duckdb, the sqlite for data science

  • FoundationDB, the database with the least errors

  • Datomic, the database with the coolest feature

  • Nix, the software that maximaze the value of $love^2 + hate^2$

  • Typst, finally a something that takes over $\LaTex2e$

  • Clojure... made simple easy

Questions?¶