diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-12-29 22:23:56 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-12-29 22:23:56 +0900 |
| commit | 4e83f1c68a4306d819994fd04b5cbd6af682bbd0 (patch) | |
| tree | f35b187013c6ab36d6eae9f857a5eb0f1e7bc286 /sample/map.in | |
| parent | 48d93c9d2366ed5eeb84758e12659ef374bb868a (diff) | |
| download | inpla-4e83f1c68a4306d819994fd04b5cbd6af682bbd0.tar.gz inpla-4e83f1c68a4306d819994fd04b5cbd6af682bbd0.zip | |
Create map.in
Diffstat (limited to 'sample/map.in')
| -rw-r--r-- | sample/map.in | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/sample/map.in b/sample/map.in new file mode 100644 index 0000000..08f457c --- /dev/null +++ b/sample/map.in @@ -0,0 +1,44 @@ +// Map operation + +// target function +inc(r)><(int i) => r~(i+1); +subPair(r)><(int m, int n) => r~(m-n); + + +// ----------- main (with the built-in Map and `%' notation) ----------- +Map(r, %inc) ~ [1,2,3]; +r; // r ->[2,3,4] + +Map(rr, %subPair) ~ [(10,2), (30,13)]; +rr; // r4 ->[8,17] + + + + +// ----------- main (without the built-in Map) ----------- +// map +map(result, f) >< [] => result~[], Eraser~f; +map(result, f) >< x:xs => Dup(f1,f2)~f, + result~w:ws, + f1 ~ (w, x), map(ws, f2)~xs; + + +// --- map application without the `%' notation --- +map(r1, (a, inc(a))) ~ [10,11,12]; +r1; // r1 ->[11,12,13] + +map(r2, (a, subPair(a))) ~ [(10,2), (30,13)]; +r2; // r2 ->[8,17] + + +// --- map application with the `%' notation --- +map(r3, %inc) ~ [1,2,3]; +r3; // r3 ->[2,3,4] + +map(r4, %subPair) ~ [(10,2), (30,13)]; +r4; // r4 ->[8,17] + + + + + |
