|
533 | 533 | "% |
534 | 534 | = fun pred l => |
535 | 535 | let aux = fun acc x => |
536 | | - if (pred x) then |
| 536 | + if pred x then |
537 | 537 | { right = acc.right @ [x], wrong = acc.wrong } |
538 | 538 | else |
539 | 539 | { right = acc.right, wrong = acc.wrong @ [x] } |
|
654 | 654 | if length <= 1 then |
655 | 655 | array |
656 | 656 | else |
657 | | - let first = %array/at% array 0 in |
658 | | - let rest = %array/slice% 1 length array in |
| 657 | + let |
| 658 | + first = %array/at% array 0, |
| 659 | + rest = %array/slice% 1 length array, |
| 660 | + in |
659 | 661 | [first] @ (flat_map (fun a => [v, a]) rest), |
660 | 662 |
|
661 | 663 | slice |
|
866 | 868 | "% |
867 | 869 | = fun f array => |
868 | 870 | let last_index = %array/length% array - 1 in |
869 | | - let last = %array/at% array last_index in |
870 | | - let rest = %array/slice% 0 last_index array in |
| 871 | + let |
| 872 | + last = %array/at% array last_index, |
| 873 | + rest = %array/slice% 0 last_index array, |
| 874 | + in |
871 | 875 | fold_right f last rest, |
872 | 876 |
|
873 | 877 | zip_with |
|
1850 | 1854 | let label_module = label in |
1851 | 1855 | let attach_message = label_module.with_message "invalid array indexing" in |
1852 | 1856 |
|
1853 | | - let ArrayIndexFirst = |
1854 | | - %contract/custom% (fun label value => |
| 1857 | + let |
| 1858 | + ArrayIndexFirst = %contract/custom% (fun label value => |
1855 | 1859 | if %typeof% value == 'Number then |
1856 | 1860 | let label = |
1857 | 1861 | label |
|
1861 | 1865 | std.contract.check std.number.Nat label value |
1862 | 1866 | else |
1863 | 1867 | 'Ok value |
1864 | | - ) |
1865 | | - in |
| 1868 | + ), |
1866 | 1869 |
|
1867 | | - let ArrayIndexSecond = fun type min_size => |
| 1870 | + ArrayIndexSecond = fun type min_size => |
1868 | 1871 | %contract/custom% (fun _label value => |
1869 | 1872 | if %typeof% min_size == 'Number && %typeof% value == 'Array then |
1870 | 1873 | let max_idx = |
|
1893 | 1896 | 'Ok value |
1894 | 1897 | else |
1895 | 1898 | 'Ok value |
1896 | | - ) |
| 1899 | + ), |
1897 | 1900 | in |
1898 | 1901 |
|
1899 | 1902 | fun type => |
|
1923 | 1926 | let label_module = label in |
1924 | 1927 | let attach_message = label_module.with_message "invalid array slice indexing" in |
1925 | 1928 |
|
1926 | | - let SliceIndexFirst = |
1927 | | - %contract/custom% (fun label value => |
1928 | | - if %typeof% value == 'Number then |
1929 | | - let label = |
1930 | | - label |
1931 | | - |> attach_message |
1932 | | - |> label_module.append_note "Expected the array slice start index to be a positive integer, got %{%to_string% value}" |
1933 | | - in |
1934 | | - std.contract.check std.number.Nat label value |
1935 | | - else |
1936 | | - 'Ok value |
1937 | | - ) |
1938 | | - in |
| 1929 | + let |
| 1930 | + SliceIndexFirst = |
| 1931 | + %contract/custom% (fun label value => |
| 1932 | + if %typeof% value == 'Number then |
| 1933 | + let label = |
| 1934 | + label |
| 1935 | + |> attach_message |
| 1936 | + |> label_module.append_note "Expected the array slice start index to be a positive integer, got %{%to_string% value}" |
| 1937 | + in |
| 1938 | + std.contract.check std.number.Nat label value |
| 1939 | + else |
| 1940 | + 'Ok value |
| 1941 | + ), |
| 1942 | + |
| 1943 | + SliceIndexSecond = fun start => |
| 1944 | + %contract/custom% (fun label value => |
| 1945 | + if %typeof% start == 'Number && %typeof% value == 'Number then |
| 1946 | + if value < start then |
| 1947 | + 'Error { |
| 1948 | + message = "invalid array slice indexing", |
| 1949 | + notes = [ |
| 1950 | + "Expected the array slice indices to satisfy `start <= end`, but got %{%to_string% start} (start) and %{%to_string% value} (end)" |
| 1951 | + ], |
| 1952 | + } |
| 1953 | + else |
| 1954 | + let label = |
| 1955 | + label |
| 1956 | + |> attach_message |
| 1957 | + |> label_module.append_note "Expected the array slice end index to be a positive integer, got %{%to_string% value}" |
| 1958 | + in |
| 1959 | + std.contract.check std.number.Nat label value |
| 1960 | + else |
| 1961 | + 'Ok value |
| 1962 | + ), |
| 1963 | + |
| 1964 | + ArraySliceArray = fun end_index => |
| 1965 | + %contract/custom% (fun _label value => |
| 1966 | + if %typeof% end_index == 'Number |
| 1967 | + && %typeof% value == 'Array |
| 1968 | + && end_index > %array/length% value then |
| 1969 | + let index_as_str = %to_string% end_index in |
| 1970 | + let size_as_str = %to_string% (%array/length% value) in |
1939 | 1971 |
|
1940 | | - let SliceIndexSecond = fun start => |
1941 | | - %contract/custom% (fun label value => |
1942 | | - if %typeof% start == 'Number && %typeof% value == 'Number then |
1943 | | - if value < start then |
1944 | 1972 | 'Error { |
1945 | 1973 | message = "invalid array slice indexing", |
1946 | 1974 | notes = [ |
1947 | | - "Expected the array slice indices to satisfy `start <= end`, but got %{%to_string% start} (start) and %{%to_string% value} (end)" |
| 1975 | + "Expected the slice end index to be between 0 and %{size_as_str} (array's length), got %{index_as_str}" |
1948 | 1976 | ], |
1949 | 1977 | } |
1950 | 1978 | else |
1951 | | - let label = |
1952 | | - label |
1953 | | - |> attach_message |
1954 | | - |> label_module.append_note "Expected the array slice end index to be a positive integer, got %{%to_string% value}" |
1955 | | - in |
1956 | | - std.contract.check std.number.Nat label value |
1957 | | - else |
1958 | | - 'Ok value |
1959 | | - ) |
1960 | | - in |
1961 | | - |
1962 | | - let ArraySliceArray = fun end_index => |
1963 | | - %contract/custom% (fun _label value => |
1964 | | - if %typeof% end_index == 'Number |
1965 | | - && %typeof% value == 'Array |
1966 | | - && end_index > %array/length% value then |
1967 | | - let index_as_str = %to_string% end_index in |
1968 | | - let size_as_str = %to_string% (%array/length% value) in |
1969 | | - |
1970 | | - 'Error { |
1971 | | - message = "invalid array slice indexing", |
1972 | | - notes = [ |
1973 | | - "Expected the slice end index to be between 0 and %{size_as_str} (array's length), got %{index_as_str}" |
1974 | | - ], |
1975 | | - } |
1976 | | - else |
1977 | | - 'Ok value |
1978 | | - ) |
| 1979 | + 'Ok value |
| 1980 | + ), |
1979 | 1981 | in |
1980 | 1982 |
|
1981 | 1983 | DependentFun |
|
2252 | 2254 | "% |
2253 | 2255 | = fun f enum_value => |
2254 | 2256 | if %enum/is_variant% enum_value then |
2255 | | - let tag = (%to_string% (%enum/get_tag% enum_value)) in |
2256 | | - let mapped = f (%enum/get_arg% enum_value) in |
| 2257 | + let |
| 2258 | + tag = (%to_string% (%enum/get_tag% enum_value)), |
| 2259 | + mapped = f (%enum/get_arg% enum_value), |
| 2260 | + in |
2257 | 2261 |
|
2258 | 2262 | %enum/make_variant% tag mapped |
2259 | 2263 | else |
|
3505 | 3509 | if length == 0 then |
3506 | 3510 | "" |
3507 | 3511 | else |
3508 | | - let first = %array/at% fragments 0 in |
3509 | | - let rest = |
3510 | | - %array/slice% 1 length fragments |
3511 | | - |> std.array.fold_left (fun acc s => acc ++ sep ++ s) "" |
| 3512 | + let |
| 3513 | + first = %array/at% fragments 0, |
| 3514 | + rest = |
| 3515 | + %array/slice% 1 length fragments |
| 3516 | + |> std.array.fold_left (fun acc s => acc ++ sep ++ s) "", |
3512 | 3517 | in |
3513 | 3518 | first ++ rest, |
3514 | 3519 |
|
|
0 commit comments