diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index 45da5a00..1142b0fe 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -82,22 +82,7 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo { // Bool prelude.types_constructors.insert( BOOL.to_string(), - vec!["True".to_string(), "False".to_string()], - ); - - prelude.values.insert( - "True".to_string(), - ValueConstructor::public( - bool(), - ValueConstructorVariant::Record { - module: "".into(), - name: "True".to_string(), - field_map: None::, - arity: 0, - location: Span::empty(), - constructors_count: 2, - }, - ), + vec!["False".to_string(), "True".to_string()], ); prelude.values.insert( @@ -115,6 +100,21 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo { ), ); + prelude.values.insert( + "True".to_string(), + ValueConstructor::public( + bool(), + ValueConstructorVariant::Record { + module: "".into(), + name: "True".to_string(), + field_map: None::, + arity: 0, + location: Span::empty(), + constructors_count: 2, + }, + ), + ); + prelude.types.insert( BOOL.to_string(), TypeConstructor { diff --git a/examples/acceptance_tests/095/lib/foo.ak b/examples/acceptance_tests/095/lib/foo.ak index 0225a2d0..66a2b591 100644 --- a/examples/acceptance_tests/095/lib/foo.ak +++ b/examples/acceptance_tests/095/lib/foo.ak @@ -101,38 +101,66 @@ fn any_list(fuzz_a: Fuzzer) -> Fuzzer> { fn any_season() -> Fuzzer { any_int - |> map( + |> and_then( fn(i) { let n = i % 3 if n == 0 { - Winter { cold: True } + any_bool() |> map(Winter) } else if n == 1 { - Spring(i) + constant(Spring(i)) } else if n == 2 { - Summer + constant(Summer) } else { - Fall + constant(Fall) } }, ) } -// Properties - -pub type Season { - Winter { cold: Bool } - Spring(Int) - Summer - Fall -} - -test prop_list(xs via any_list(any_season())) { - xs != [Winter(True)] || xs != [Winter(False)] -} - fn length(xs: List) -> Int { when xs is { [] -> 0 [_, ..tail] -> 1 + length(tail) } } + +fn filter(xs: List, f: fn(a) -> Bool) -> List { + when xs is { + [] -> + [] + [head, ..tail] -> + if f(head) { + [head, ..filter(tail, f)] + } else { + filter(tail, f) + } + } +} + +// Properties + +pub type Season { + Winter(Bool) + Spring(Int) + Summer + Fall +} + +// test prop_is_never_summer(xs via any_list(any_season())) { +// filter(xs, fn(x) { x == Summer }) == [] +// } + +test prop_is_always_cold_in_winter(xs via any_list(any_season())) { + is_always_cold_in_winter(xs) +} + +test prop_is_always_cold_in_winter_2() { + is_always_cold_in_winter([Winter(True)]) +} + +fn is_always_cold_in_winter(xs: List) -> Bool { + when xs is { + [Winter(cold), ..tail] -> cold && is_always_cold_in_winter(tail) + _ -> True + } +}