-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.mapal
More file actions
38 lines (35 loc) · 1.4 KB
/
Copy pathvector.mapal
File metadata and controls
38 lines (35 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// vector.mapal
//
// ASPIRATIONAL SKETCH — DOES NOT COMPILE TODAY.
//
// This file shows the post-Core generics dialect, not Mapal-Core:
// - type parameters on functions (`zip<A, B, N>`, `vec_add<N: i32>`) — not in
// the grammar; the parser recovers with P0001 ("expected `(` after function
// name"). Generic type ARGUMENTS in type position are the parsed case and
// are rejected with P0103.
// - a range literal (`[0..N]`) — not in the grammar.
// - fixed arrays parameterized by a size variable (`[A; N]`) — Mapal-Core
// requires a literal size (`[A; 16]`).
// - a destructuring op-block parameter (`map { (x, y) -> … }`) — rejected
// with P0116.
// - a call expression (`vec_add(a, b)` in `main`) — rejected with P0108;
// Mapal-Core calls are tuple-input flows: `(a, b) -> vec_add`.
//
// The test suite therefore excludes this file from the in-Core example set
// (mapal-rewrite/tests/identity.rs: "the out-of-Core generics sketch"). For the
// in-Core version of this program — monomorphic, via the ADR-0018 `zip`
// builtin — see vector_add.mapal.
fn zip<A, B, N>(a: [A; N], b: [B; N]) -> [(A, B); N] {
[0..N] -> map { i ->
(a[i], b[i])
} -> ret;
}
fn vec_add<N: i32>(a: [i32; N], b: [i32; N]) -> [i32; 16] {
// This
(a, b) -> zip -> map { (x, y) ->
x + y
} -> ret;
}
fn main() {
vec_add([1, 2, 3, 4], [5, 6, 7, 8]) -> print;
}