slide init
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
---
|
||||||
|
theme: dracula
|
||||||
|
paginate: true
|
||||||
|
_paginate: false
|
||||||
|
footer: Topics in Compilers and Concurrency · Julius Fischer · 10.06.2026
|
||||||
|
_footer: ""
|
||||||
|
style: |
|
||||||
|
h1 {
|
||||||
|
position: absolute;
|
||||||
|
top: 60px;
|
||||||
|
left: 75px;
|
||||||
|
right: 75px;
|
||||||
|
}
|
||||||
|
---
|
||||||
|
|
||||||
|
# Destination Calculus:
|
||||||
|
## A Linear 𝜆-Calculus for Purely Functional Memory Writes
|
||||||
|
### Topics in Compiler and Concurrency
|
||||||
|
#### Julius Fischer
|
||||||
|
|
||||||
|
###### 10. Juni 2026
|
||||||
|
|
||||||
|
---
|
||||||
|
# What are Destinations?
|
||||||
|
- Destination Passing Style
|
||||||
|
- Imperative
|
||||||
|
- Function takes destination instead of returning structure
|
||||||
|
---
|
||||||
|
# Example in C
|
||||||
|
```
|
||||||
|
int* vec_add(int v1[], int v2[], int size) {
|
||||||
|
int* res = malloc(size * sizeof(int));
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
res[i] = v1[i] + v2[i];
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Add an 'out parameter'
|
||||||
|
```
|
||||||
|
void dps_vec_add(int res[], int v1[], int v2[], int size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
res[i] = v1[i] + v2[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
# Motivation for DPS
|
||||||
|
- Typical functional map implementation
|
||||||
|
```
|
||||||
|
map f (x:xs) = (f x : map f xs1)
|
||||||
|
> (f x : map f xs)
|
||||||
|
> (map f x1 : (f x2 : map f xs2))
|
||||||
|
> ...
|
||||||
|
```
|
||||||
|
- Not tail recursive
|
||||||
|
- Performance issue
|
||||||
|
- Inefficient stack growth
|
||||||
|
```
|
||||||
|
map f (x:xs) dest = map f xs (push dest (f x))
|
||||||
|
> map f xs1 (push dest (f x1))
|
||||||
|
> map f xs2 (push dest (f x2))
|
||||||
|
```
|
||||||
|
---
|
||||||
|
# DPS in functional languages
|
||||||
|
- Just add pointers to mutable data?
|
||||||
|
- $Int \mapsto Int \mapsto Int \mapsto \textcolor{red}{T}$
|
||||||
|
- $\textcolor{red}{T *}\mapsto Int \mapsto Int \mapsto Int \mapsto Void$
|
||||||
|
|
||||||
|
---
|
||||||
|
# Destination Calculus
|
||||||
|
- It's
|
||||||
|
|
||||||
|
---
|
||||||
|
# Referenes
|
||||||
+1
-1
@@ -5,4 +5,4 @@ all: clean bib compile
|
|||||||
clean:
|
clean:
|
||||||
rm -rf ./out
|
rm -rf ./out
|
||||||
compile:
|
compile:
|
||||||
marp src.md --theme ./themes/academic.css -o out/presentation.html
|
marp main.md --theme ./themes/academic.css -o out/presentation.html
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
---
|
|
||||||
theme: dracula
|
|
||||||
paginate: true
|
|
||||||
_paginate: false
|
|
||||||
footer: Mini-Haskell · Julius Fischer · 19.11.2024
|
|
||||||
_footer: ""
|
|
||||||
---
|
|
||||||
|
|
||||||
# Destination Calculus:
|
|
||||||
## A Linear 𝜆-Calculus for Purely Functional Memory Writes
|
|
||||||
### Technische Fakultät Freiburg
|
|
||||||
#### Julius Fischer
|
|
||||||
|
|
||||||
###### 10. Juni 2026
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Referenes
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void pretty_print(uint size, int v[]) {
|
||||||
|
printf("[");
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
printf("%d,", v[i]);
|
||||||
|
printf("]\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int* vec_add(int v1[], int v2[], int size) {
|
||||||
|
int* res = malloc(size * sizeof(int));
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
res[i] = v1[i] + v2[i];
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dps_vec_add(int res[], int v1[], int v2[], int size) {
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
res[i] = v1[i] + v2[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SIZE 5
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
int v1[SIZE] = {1, 2, 4, 5, 10};
|
||||||
|
int v2[SIZE] = {2, 2, 1, 2, 1};
|
||||||
|
int *added = vec_add(v1, v2, SIZE);
|
||||||
|
pretty_print(SIZE, added);
|
||||||
|
|
||||||
|
int dest[SIZE] = {2, 2, 1, 2, 1};
|
||||||
|
dps_vec_add(dest, v1, v2, SIZE);
|
||||||
|
pretty_print(SIZE, dest);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user