Skip to content

Commit 3789478

Browse files
committed
replace @immut/list with @list
1 parent 53c7ff5 commit 3789478

22 files changed

+102
-110
lines changed

src/falsify/driver.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn[T] append_success(
5151
{
5252
..acc,
5353
rng,
54-
success: Cons(success, acc.success),
54+
success: acc.success.add(success),
5555
todo: acc.todo - 1,
5656
discarded: 0,
5757
}
@@ -61,7 +61,7 @@ fn[T] append_success(
6161
pub fn[T] init_state(opt : Config) -> DriverState[T] {
6262
{
6363
rng: opt.replay.unwrap_or(@quickcheck/splitmix.new()),
64-
success: Nil,
64+
success: @list.empty(),
6565
todo: opt.tests,
6666
discarded: 0,
6767
total_discard: 0,
@@ -101,7 +101,7 @@ pub fn[T, E] falsify(
101101
let success : Success[T] = { result: x, seed: now.clone(), run }
102102
if run.deterministic {
103103
match (acc.success, acc.total_discard) {
104-
(Nil, 0) => (Cons(success, Nil), 0, None)
104+
(Empty, 0) => (@list.singleton(success), 0, None)
105105
_ => abort("impossible")
106106
}
107107
} else {

src/falsify/falsify.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package "moonbitlang/quickcheck/falsify"
22

33
import(
4-
"moonbitlang/core/immut/list"
4+
"moonbitlang/core/list"
55
"moonbitlang/core/quickcheck/splitmix"
66
)
77

src/falsify/property.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///|
2-
pub typealias @immut/list.T as List
2+
pub typealias @list.T as List
33

44
///|
55
struct TestRun {
@@ -10,7 +10,7 @@ struct TestRun {
1010

1111
///|
1212
pub fn init_test_run() -> TestRun {
13-
{ log: Nil, deterministic: true, labels: @immut/hashmap.new() }
13+
{ log: @list.empty(), deterministic: true, labels: @immut/hashmap.new() }
1414
}
1515

1616
///|
@@ -55,7 +55,7 @@ pub fn[T, E] discard() -> Property[T, E] {
5555
///|
5656
pub fn info(msg : String) -> Property[Unit, String] {
5757
mk_property(fn(run) {
58-
pure((TestPassed(()), { ..run, log: Cons(msg, run.log) }))
58+
pure((TestPassed(()), { ..run, log: run.log.add(msg) }))
5959
})
6060
}
6161

@@ -87,7 +87,7 @@ pub fn[T, E] gen(f : (T) -> String?, g : Gen[T]) -> Property[T, E] {
8787
fn(x) {
8888
match f(x) {
8989
None => (TestPassed(x), { ..run, deterministic: false })
90-
Some(msg) => (TestPassed(x), { ..run, log: Cons(msg, run.log) })
90+
Some(msg) => (TestPassed(x), { ..run, log: run.log.add(msg) })
9191
}
9292
}
9393
}

src/feat/enumerable.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ pub impl Enumerable for UInt64 with enumerate() {
3737
}
3838

3939
///|
40-
pub impl[E : Enumerable] Enumerable for @immut/list.T[E] with enumerate() {
40+
pub impl[E : Enumerable] Enumerable for @list.T[E] with enumerate() {
4141
consts(
42-
@immut/list.of([
43-
singleton(Nil),
44-
unary(@utils.pair_function(@immut/list.Cons(_, _))),
42+
@list.of([
43+
singleton(@list.empty()),
44+
unary(@utils.pair_function(fn(e : E, lst : @list.T[E]) { lst.add(e) })),
4545
]),
4646
)
4747
}

src/feat/enumerate.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn[T, U] app(f : Enumerate[(T) -> U], e : Enumerate[T]) -> Enumerate[U] {
7575
}
7676

7777
///|
78-
pub fn[T] consts(ls : @immut/list.T[Enumerate[T]]) -> Enumerate[T] {
78+
pub fn[T] consts(ls : @list.T[Enumerate[T]]) -> Enumerate[T] {
7979
pay(fn() { ls.fold(union, init=empty()) })
8080
}
8181

src/feat/feat.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package "moonbitlang/quickcheck/feat"
22

33
import(
44
"moonbitlang/core/bigint"
5-
"moonbitlang/core/immut/list"
5+
"moonbitlang/core/list"
66
"moonbitlang/quickcheck/lazy"
77
)
88

src/feat/finite.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ pub fn[M] fin_mconcat(val : LazyList[Finite[M]]) -> Finite[M] {
107107
}
108108

109109
///|
110-
pub fn[T] to_array(self : Finite[T]) -> (BigInt, @immut/list.T[T]) {
110+
pub fn[T] to_array(self : Finite[T]) -> (BigInt, @list.T[T]) {
111111
(
112112
self.fCard,
113-
loop (self.fCard, @immut/list.Nil) {
113+
loop (self.fCard, @list.empty()) {
114114
(0, acc) => acc
115-
(n, acc) => continue (n - 1, Cons((self.fIndex)(n), acc))
115+
(n, acc) => continue (n - 1, acc.add((self.fIndex)(n)))
116116
},
117117
)
118118
}

src/gen.mbt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn[T] frequency(arr : Array[(Int, Gen[T])]) -> Gen[T] {
268268

269269
///| Chooses one of the given generators, with a weighted random distribution.
270270
/// @alert unsafe "Panics if the list is empty or total weight is less than one"
271-
pub fn[T] frequency_list(lst : @immut/list.T[(Int, T)]) -> Gen[T] {
271+
pub fn[T] frequency_list(lst : @list.T[(Int, T)]) -> Gen[T] {
272272
lst
273273
.to_array()
274274
.map(fn(x) {
@@ -279,10 +279,10 @@ pub fn[T] frequency_list(lst : @immut/list.T[(Int, T)]) -> Gen[T] {
279279
}
280280

281281
///| Generate a list of elements from individual generators
282-
pub fn[T] flatten_list(lst : @immut/list.T[Gen[T]]) -> Gen[@immut/list.T[T]] {
282+
pub fn[T] flatten_list(lst : @list.T[Gen[T]]) -> Gen[@list.T[T]] {
283283
match lst {
284-
Nil => pure(Nil)
285-
Cons(x, xs) => liftA2(@immut/list.T::Cons(_, _), x, flatten_list(xs))
284+
Empty => pure(@list.empty())
285+
More(x, tail=xs) => liftA2(@list.T::add, flatten_list(xs), x)
286286
}
287287
}
288288

@@ -315,7 +315,7 @@ pub fn[T] one_of(arr : Array[Gen[T]]) -> Gen[T] {
315315

316316
///| Randomly uses one of the given generators in list
317317
/// @alert unsafe "Panics if the list is empty"
318-
pub fn[T] one_of_list(lst : @immut/list.T[T]) -> Gen[T] {
318+
pub fn[T] one_of_list(lst : @list.T[T]) -> Gen[T] {
319319
int_bound(lst.length()).fmap(fn(x) { lst.unsafe_nth(x) })
320320
}
321321

@@ -400,23 +400,20 @@ pub fn char_range(lo : Char, hi : Char) -> Gen[Char] {
400400
}
401401

402402
///|
403-
pub fn[T] list_with_size(size : Int, gen : Gen[T]) -> Gen[@immut/list.T[T]] {
404-
loop (size, pure(@immut/list.Nil)) {
403+
pub fn[T] list_with_size(size : Int, gen : Gen[T]) -> Gen[@list.T[T]] {
404+
loop (size, pure(@list.empty())) {
405405
(n, acc) =>
406406
if n <= 0 {
407407
break acc
408408
} else {
409-
continue (n - 1, liftA2(@immut/list.T::Cons(_, _), gen, acc))
409+
continue (n - 1, liftA2(@list.T::add, acc, gen))
410410
}
411411
}
412412
}
413413

414414
///|
415-
pub fn[T : Compare] sorted_list(
416-
size : Int,
417-
gen : Gen[T]
418-
) -> Gen[@immut/list.T[T]] {
419-
list_with_size(size, gen).fmap(@immut/list.T::sort)
415+
pub fn[T : Compare] sorted_list(size : Int, gen : Gen[T]) -> Gen[@list.T[T]] {
416+
list_with_size(size, gen).fmap(@list.T::sort)
420417
}
421418

422419
///|

src/internal_shrinking/internal_shrinking.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package "moonbitlang/quickcheck/internal_shrinking"
22

33
import(
4-
"moonbitlang/core/immut/list"
4+
"moonbitlang/core/list"
55
)
66

77
// Values

src/internal_shrinking/shrink_tree.mbt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,32 @@ pub impl[T : Show] Show for ShrinkTree[T] with output(self, logger) {
1010
}
1111

1212
///|
13-
pub fn[T : Show] draw(
14-
self : ShrinkTree[T],
15-
depth : Int
16-
) -> @immut/list.T[String] {
13+
pub fn[T : Show] draw(self : ShrinkTree[T], depth : Int) -> @list.T[String] {
1714
if depth == 0 {
18-
return Cons("limit reach", Nil)
15+
return @list.singleton("limit reach")
1916
}
20-
fn shift(first : String, other : String, x : @immut/list.T[String]) {
17+
fn shift(first : String, other : String, x : @list.T[String]) {
2118
@lazy.zip_lazy_normal(
2219
String::op_add,
2320
@lazy.Cons(first, @lazy.LazyRef::from_value(@lazy.repeat(other))),
2421
x,
2522
)
2623
}
2724

28-
fn draw_sub(l : @immut/list.T[ShrinkTree[T]]) {
25+
fn draw_sub(l : @list.T[ShrinkTree[T]]) {
2926
match l {
30-
@immut/list.Nil => @immut/list.Nil
31-
Cons(t, Nil) => Cons("│", shift("└─ ", " ", t.draw(depth - 1)))
32-
Cons(t, ts) =>
33-
@immut/list.T::concat(
34-
Cons("│", shift("├─ ", "│ ", t.draw(depth - 1))),
27+
Empty => @list.empty()
28+
More(t, tail=Empty) =>
29+
shift("└─ ", " ", t.draw(depth - 1)).add("│")
30+
More(t, tail=ts) =>
31+
@list.T::concat(
32+
shift("├─ ", "│ ", t.draw(depth - 1)).add("│"),
3533
draw_sub(ts),
3634
)
3735
}
3836
}
3937

40-
Cons(self.leaf.to_string(), draw_sub(@immut/list.from_iter(self.branch)))
38+
draw_sub(@list.from_iter(self.branch)).add(self.leaf.to_string())
4139
}
4240

4341
///|

0 commit comments

Comments
 (0)