@explorable-viz/fluid 0.9.8 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/fluid/fluid/lib/pi.fld +1 -0
  2. package/dist/fluid/fluid/lib/prelude.fld +213 -251
  3. package/dist/fluid/shared/fluid.mjs +4585 -1030
  4. package/dist/fluid/shared/load-figure.js +4601 -7056
  5. package/dist/fluid/shared/webtest-lib.js +3958 -3958
  6. package/package.json +1 -1
  7. package/website/article/convolution/index.html +10 -3
  8. package/website/article/fluid/1805.02474v1-10.fld +46 -0
  9. package/website/article/fluid/bar-chart-line-chart.fld +37 -0
  10. package/website/article/fluid/convolution/emboss.fld +3 -5
  11. package/website/article/fluid/convolution/testImage.fld +9 -7
  12. package/website/article/fluid/convolution.fld +25 -23
  13. package/website/article/fluid/dataset/renewable-new.json +91 -0
  14. package/website/article/fluid/dataset/scigen/1805.02474v1-10.json +17 -0
  15. package/website/article/fluid/dataset/scigen/_1805_02474v1_10.fld +2 -0
  16. package/website/article/fluid/methane.fld +1 -1
  17. package/website/article/fluid/moving-average.fld +22 -19
  18. package/website/article/fluid/non-renewables.fld +29 -21
  19. package/website/article/fluid/nonRenewables.fld +5 -2
  20. package/website/article/fluid/renewables.fld +1 -0
  21. package/website/article/fluid/scigen.fld +48 -0
  22. package/website/article/fluid/util.fld +39 -0
  23. package/website/article/index.html +3 -1
  24. package/website/article/moving-average/index.html +8 -2
  25. package/website/article/non-renewables/index.html +8 -2
  26. package/website/article/renewables-linked/index.html +60 -0
  27. package/website/article/scigen-1805.02474v1-10/index.html +50 -0
  28. package/website/article/test.mjs +5 -0
  29. package/website/article/convolution/spec.json +0 -6
  30. package/website/article/moving-average/spec.json +0 -6
  31. package/website/article/non-renewables/spec.json +0 -6
@@ -0,0 +1 @@
1
+ def pi: 3
@@ -1,276 +1,238 @@
1
- -- "Num" throughout means (Int + Float).
1
+ def and(False, y): False
2
+ def and(True, y): y
2
3
 
3
- -- Bool -> Bool
4
- let and False y = False;
5
- and True y = y;
4
+ def or(True, y): True
5
+ def or(False, y): y
6
6
 
7
- -- Bool -> Bool
8
- let or True y = True;
9
- or False y = y;
7
+ def not(True): False
8
+ def not(False): True
10
9
 
11
- -- Bool -> Bool
12
- let not True = False;
13
- not False = True;
10
+ def compare(x, y):
11
+ if x > y: GT
12
+ else:
13
+ if x < y: LT
14
+ else: EQ
14
15
 
15
- -- Int -> Int -> Ordering
16
- let compare x y =
17
- if x > y
18
- then GT
19
- else if x < y
20
- then LT
21
- else EQ;
16
+ def negate: (-)(0)
22
17
 
23
- -- Num -> Num
24
- let negate = (-) 0;
18
+ def logBase(x, y): log(y) / log(x)
25
19
 
26
- -- Log of x in base y.
27
- -- Float -> Float -> Float
28
- let logBase x y = log y / log x;
20
+ def ceilingToNearest(n, m): ceiling(n / m) * m
29
21
 
30
- -- Float -> Float -> Float
31
- let ceilingToNearest n m =
32
- ceiling (n / m) * m;
22
+ def compose(f, g, x): f(g(x))
33
23
 
34
- -- (b -> c) -> (a -> b) -> a -> c
35
- -- Want infix <<<
36
- let compose f g x = f (g x);
24
+ def curry(f, x, y): f((x, y))
37
25
 
38
- -- ((a, b) -> c) -> a -> b -> c
39
- let curry f x y = f (x, y);
26
+ def uncurry(f, (x, y)): f(x, y)
40
27
 
41
- -- (a -> b -> c) -> (a, b) -> c
42
- let uncurry f (x, y) = f x y;
28
+ def const(x, _): x
43
29
 
44
- -- a -> b -> a
45
- let const x _ = x;
30
+ def first(f, (a, c)): (f(a), c)
46
31
 
47
- -- (a -> b) -> (a, c) -> (b, c)
48
- let first f (a, c) = (f a, c);
32
+ def snd((_, y)): y
49
33
 
50
- -- (a, b) -> b
51
- let snd (_, y) = y;
34
+ def second(f, (c, a)): (c, f(a))
52
35
 
53
- -- (a -> b) -> (c, a) -> (c, b)
54
- let second f (c, a) = (c, f a);
36
+ def flip(f, x, y): f(y, x)
55
37
 
56
- -- (a -> b -> c) -> b -> a -> c
57
- let flip f x y = f y x;
38
+ def fst((x, _)): x
58
39
 
59
- -- (a, b) -> a
60
- let fst (x, _) = x;
40
+ def id(x): x
61
41
 
62
- -- a -> a
63
- let id x = x;
42
+ def prod(f, g, x): (f(x), g(x))
64
43
 
65
- -- (a -> b) -> (a -> c) -> a -> (b, c)
66
- -- Want infix &&&
67
- let prod f g x = (f x, g x);
44
+ def swap((a, b)): (b, a)
68
45
 
69
- -- (a, b) -> (b, a)
70
- let swap (a, b) = (b, a);
46
+ def head([]):
47
+ error("Can't take head of empty list")
48
+ def head(x :| _): x
71
49
 
72
- -- List a -> a
73
- let head [] = error "Can't take head of empty list";
74
- head (x : _) = x;
50
+ def tail([]):
51
+ error("Can't take tail of empty list")
52
+ def tail(_ :| xs): xs
75
53
 
76
- -- List a -> List a
77
- let tail [] = error "Can't take tail of empty list";
78
- tail (_ : xs) = xs;
54
+ def elem(x, []): False
55
+ def elem(x, y :| xs):
56
+ x == y |or| elem(x, xs)
79
57
 
80
- -- Eq a => a -> List a -> Bool
81
- let elem x [] = False;
82
- elem x (x' : xs) = (x == x') `or` (elem x xs);
58
+ def find(p, []): error("not found")
59
+ def find(p, x :| xs):
60
+ if p(x): Some(x)
61
+ else: find(p, xs)
83
62
 
84
- -- (a -> Bool) -> List a -> Option a
85
- let find p [] = error "not found";
86
- find p (x : xs) = if p x then Some x else find p xs;
63
+ def findWithKey(fname, fval, table):
64
+ find((lambda y: y[fname] == fval), table)
87
65
 
88
- -- String -> String -> List Dict -> Option Dict
89
- let findWithKey fname fval table = find (fun y -> y.[fname] == fval) table;
66
+ def fromSome(option):
67
+ match option:
68
+ case None:
69
+ error("Expected Some!")
70
+ case Some(x): x
90
71
 
91
- let fromSome option = match option as {
92
- None -> error "Expected Some!";
93
- Some x -> x
94
- };
95
-
96
- -- (a -> Bool) -> List a -> List a
97
- let filter p [] = [];
98
- filter p (x : xs) =
99
- let ys = filter p xs in
100
- if p x then x : ys else ys;
101
-
102
- -- (a -> Option b) -> List a -> List b
103
- let filterMap p [] = [];
104
- filterMap p (x : xs) =
105
- match p x as {
106
- None -> filterMap f xs;
107
- Some y -> y : filterMap f xs
108
- };
109
-
110
- -- (a -> b -> a) -> a -> List b -> a
111
- let foldl op z [] = z;
112
- foldl op z (x : xs) = foldl op (op z x) xs;
113
-
114
- -- (a -> b -> a) -> List b -> a
115
- let foldl1 op (x : xs) = foldl op x xs;
116
-
117
- -- (a -> b -> b) -> b -> List a -> b
118
- let foldr op z [] = z;
119
- foldr op z (x : xs) = op x (foldr op z xs);
120
-
121
- -- (a -> b -> b) -> List a -> b
122
- let foldr1 op [x] = x;
123
- foldr1 op (x : y : xs) = op x (foldr1 op (y : xs));
124
-
125
- -- (a -> b -> a) -> a -> List b -> List a
126
- let scanl1 op z xs =
127
- let go x continue acc =
128
- let next = op acc x in
129
- next : continue next in
130
- foldr go (const []) xs z;
131
-
132
- -- (a -> b -> a) -> a -> List b -> List a
133
- let scanl op z xs =
134
- z : scanl1 op z xs;
135
-
136
- -- (a -> b) -> List a -> List b
137
- let map f [] = [];
138
- map f (x : xs) = f x : map f xs;
139
-
140
- -- (List a, List a) -> List a
141
- let append ([], ys) = ys;
142
- append (x : xs, ys) = x : append (xs, ys);
143
-
144
- -- List a -> List -> List a
145
- -- Want infix ++
146
- let concat2 [] ys = ys;
147
- concat2 (x : xs) ys = x : concat2 xs ys;
148
-
149
- -- List (List a) -> List a
150
- let concat = foldl concat2 [];
151
-
152
- -- (a -> List b) -> List a -> List b
153
- let concatMap f xs = concat (map f xs);
154
-
155
- -- List a -> a -> List a
156
- let intersperse [] _ = [];
157
- intersperse [x] _ = [x];
158
- intersperse (x : y : ys) sep = x : sep : intersperse (y : ys) sep;
159
-
160
- -- Int -> (a -> a) -> a -> List a
161
- let iterate n f z =
162
- if n == 0 then [] else z : map f (iterate (n - 1) f z);
163
-
164
- -- List Int -> Int
165
- let sum = foldr (+) 0;
166
-
167
- -- List a -> a
168
- let last [x] = x;
169
- last (x : y : ys) = last (y : ys);
170
-
171
- -- List a -> Int
172
- let length [] = 0;
173
- length (_ : xs) = 1 + length xs;
174
-
175
- -- List a -> List a
176
- let reverse [] = [];
177
- reverse (x : xs) = append (reverse xs, [x]);
178
-
179
- -- Int -> a -> List a
180
- let repeat = flip iterate id;
181
-
182
- -- Int -> List a -> List a
183
- let take n xs =
184
- if n <= 0
185
- then []
186
- else match xs as {
187
- [] -> [];
188
- x : xs -> x : take (n - 1) xs
189
- };
190
-
191
- -- Int -> List a -> List a
192
- let drop n xs =
193
- if n <= 0
194
- then xs
195
- else match xs as {
196
- [] -> [];
197
- _ : xs -> drop (n - 1) xs
198
- };
199
-
200
- -- Int -> List a -> List a
201
- let lastN n xs =
202
- foldl (compose const (drop 1)) xs (drop n xs);
203
-
204
- -- Expects non-negative integer as first argument and non-empty list as second argument.
205
- -- Int -> List a -> a
206
- let nth n (x : xs) =
207
- if n == 0 then x else nth (n - 1) xs;
208
-
209
- -- Matrix Int -> Int -> Int -> Int
210
- let nth2 i j xss =
211
- nth (j - 1) (nth (i - 1) xss);
212
-
213
- -- Partial; requires k to be in the map.
214
- -- Int -> List (Int, b) -> b
215
- let lookup k [] = error "Key not found in map";
216
- lookup k ((k', v) : kvs) =
217
- if k == k' then v else lookup k kvs;
218
-
219
- -- Int -> Int -> Int
220
- let max n m =
221
- if n > m then n else m;
222
-
223
- -- Int -> Int -> Int
224
- let min n m =
225
- if n < m then n else m;
226
-
227
- -- List Int -> Int
228
- let maximum = foldr1 max;
229
-
230
- -- List Int -> Int
231
- let minimum = foldr1 min;
232
-
233
- -- List (a, b) -> (List a, List b)
234
- let unzip [] = ([], []);
235
- unzip ((x, y) : zs) =
236
- let (xs, ys) = unzip zs in
237
- (x : xs, y : ys);
238
-
239
- -- (a -> b -> c) -> List a -> List b -> List c
240
- let zipWith op [] ys = [];
241
- zipWith op (x : xs) [] = [];
242
- zipWith op (x : xs) (y : ys) = op x y : zipWith op xs ys;
243
-
244
- -- List a -> List b -> List (a, b)
245
- let zip = zipWith (curry id);
246
-
247
- -- Int -> Int -> List Int
248
- let enumFromTo n m =
249
- if n <= m then n : [n + 1 .. m] else [];
250
-
251
- let range (m1, n1) (m2, n2) =
252
- [ (i1, i2) | i1 <- [m1 .. m2], i2 <- [n1 .. n2] ];
253
-
254
- -- Int -> Int -> Int
255
- let abs x y =
256
- if x - y < 0 then negate (x - y) else (x - y);
257
-
258
- -- Eq a => [a] -> [a]
259
- let nub xs =
260
- let nub' [] _ = [];
261
- nub' (x : xs) ys = if x `elem` ys then nub' xs ys else x : nub' xs (x : ys) in
262
- nub' xs [];
263
-
264
- -- Int -> Int -> [a] -> [a]
265
- let slice begin end xs =
266
- take (end - begin) (drop begin xs);
267
-
268
-
269
- -- (a -> Boolean) -> List a -> (List a, List a)
270
- let splitOn p data =
271
- let go fls trs [] = (reverse fls, reverse trs);
272
- go fls trs (x : xs) =
273
- if p x
274
- then go fls (x : trs) xs
275
- else go (x : fls) trs xs
276
- in go [] [] data;
72
+ def filter(p, []): []
73
+ def filter(p, x :| xs):
74
+ def ys: filter(p, xs)
75
+
76
+ if p(x): x :| ys
77
+ else: ys
78
+
79
+ def filterMap(p, []): []
80
+ def filterMap(p, x :| xs):
81
+ match p(x):
82
+ case None: filterMap(f, xs)
83
+ case Some(y):
84
+ y :| filterMap(f, xs)
85
+
86
+ def foldl(op, z, []): z
87
+ def foldl(op, z, x :| xs):
88
+ foldl(op, op(z, x), xs)
89
+
90
+ def foldl1(op, x :| xs): foldl(op, x, xs)
91
+
92
+ def foldr(op, z, []): z
93
+ def foldr(op, z, x :| xs):
94
+ op(x, foldr(op, z, xs))
95
+
96
+ def foldr1(op, [x]): x
97
+ def foldr1(op, x :| y :| xs):
98
+ op(x, foldr1(op, y :| xs))
99
+
100
+ def scanl1(op, z, xs):
101
+ def go(x, continue, acc):
102
+ def next: op(acc, x)
103
+
104
+ next :| continue(next)
105
+
106
+ foldr(go, const([]), xs, z)
107
+
108
+ def scanl(op, z, xs):
109
+ z :| scanl1(op, z, xs)
110
+
111
+ def map(f, []): []
112
+ def map(f, x :| xs): f(x) :| map(f, xs)
113
+
114
+ def append(([], ys)): ys
115
+ def append((x :| xs, ys)):
116
+ x :| append((xs, ys))
117
+
118
+ def concat2([], ys): ys
119
+ def concat2(x :| xs, ys):
120
+ x :| concat2(xs, ys)
121
+
122
+ def concat: foldl(concat2, [])
123
+
124
+ def concatMap(f, xs): concat(map(f, xs))
125
+
126
+ def intersperse([], _): []
127
+ def intersperse([x], _): [x]
128
+ def intersperse(x :| y :| ys, sep):
129
+ x :| sep :| intersperse(y :| ys, sep)
130
+
131
+ def iterate(n, f, z):
132
+ if n == 0: []
133
+ else:
134
+ z :| map(f, iterate(n - 1, f, z))
135
+
136
+ def sum: foldr((+), 0)
137
+
138
+ def last([x]): x
139
+ def last(x :| y :| ys): last(y :| ys)
140
+
141
+ def length([]): 0
142
+ def length(_ :| xs): 1 + length(xs)
143
+
144
+ def reverse([]): []
145
+ def reverse(x :| xs):
146
+ append((reverse(xs), [x]))
147
+
148
+ def repeat: flip(iterate, id)
149
+
150
+ def take(n, xs):
151
+ if n <= 0: []
152
+ else:
153
+ match xs:
154
+ case []: []
155
+ case x :| xs:
156
+ x :| take(n - 1, xs)
157
+
158
+ def drop(n, xs):
159
+ if n <= 0: xs
160
+ else:
161
+ match xs:
162
+ case []: []
163
+ case _ :| xs: drop(n - 1, xs)
164
+
165
+ def lastN(n, xs):
166
+ foldl(compose(const, drop(1)), xs, drop(n, xs))
167
+
168
+ def nth(n, x :| xs):
169
+ if n == 0: x
170
+ else: nth(n - 1, xs)
171
+
172
+ def nth2(i, j, xss):
173
+ nth(j - 1, nth(i - 1, xss))
174
+
175
+ def lookup(k, []):
176
+ error("Key not found in map")
177
+ def lookup(k, (k_, v) :| kvs):
178
+ if k == k_: v
179
+ else: lookup(k, kvs)
180
+
181
+ def max(n, m):
182
+ if n > m: n
183
+ else: m
184
+
185
+ def min(n, m):
186
+ if n < m: n
187
+ else: m
188
+
189
+ def maximum: foldr1(max)
190
+
191
+ def minimum: foldr1(min)
192
+
193
+ def unzip([]): ([], [])
194
+ def unzip((x, y) :| zs):
195
+ def (xs, ys): unzip(zs)
196
+
197
+ (x :| xs, y :| ys)
198
+
199
+ def zipWith(op, [], ys): []
200
+ def zipWith(op, x :| xs, []): []
201
+ def zipWith(op, x :| xs, y :| ys):
202
+ op(x, y) :| zipWith(op, xs, ys)
203
+
204
+ def zip: zipWith(curry(id))
205
+
206
+ def enumFromTo(n, m):
207
+ if n <= m: n :| [n + 1 .. m]
208
+ else: []
209
+
210
+ def range((m1, n1), (m2, n2)):
211
+ [(i1, i2) for i1 in [m1 .. m2] for i2 in [n1 .. n2]]
212
+
213
+ def abs(x, y):
214
+ if x - y < 0: negate(x - y)
215
+ else: x - y
216
+
217
+ def nub(xs):
218
+ def nub_([], _): []
219
+ def nub_(x :| xs, ys):
220
+ if x |elem| ys: nub_(xs, ys)
221
+ else:
222
+ x :| nub_(xs, x :| ys)
223
+
224
+ nub_(xs, [])
225
+
226
+ def slice(begin, end, xs):
227
+ take(end - begin, drop(begin, xs))
228
+
229
+ def splitOn(p, data):
230
+ def go(fls, trs, []):
231
+ (reverse(fls), reverse(trs))
232
+ def go(fls, trs, x :| xs):
233
+ if p(x):
234
+ go(fls, x :| trs, xs)
235
+ else:
236
+ go(x :| fls, trs, xs)
237
+
238
+ go([], [], data)