Added contains
functions in List and Option. Fixed one type error catch
This commit is contained in:
parent
ed5447e430
commit
7e32ef57c2
@ -700,6 +700,13 @@ List.last(l : list('a)) : option('a)
|
|||||||
Returns `Some` of the last element of a list or `None` if the list is empty.
|
Returns `Some` of the last element of a list or `None` if the list is empty.
|
||||||
|
|
||||||
|
|
||||||
|
### contains
|
||||||
|
```
|
||||||
|
List.contains(e : 'a, l : list('a)) : bool
|
||||||
|
```
|
||||||
|
Checks if list `l` contains element `e`. Equivalent to `List.find(x => x == e, l) != None`.
|
||||||
|
|
||||||
|
|
||||||
### find
|
### find
|
||||||
```
|
```
|
||||||
List.find(p : 'a => bool, l : list('a)) : option('a)
|
List.find(p : 'a => bool, l : list('a)) : option('a)
|
||||||
@ -1040,6 +1047,13 @@ Option.force(o : option('a)) : 'a
|
|||||||
Forcefully escapes `option` wrapping assuming it is `Some`. Throws error on `None`.
|
Forcefully escapes `option` wrapping assuming it is `Some`. Throws error on `None`.
|
||||||
|
|
||||||
|
|
||||||
|
### contains
|
||||||
|
```
|
||||||
|
Option.contains(e : 'a, o : option('a)) : bool
|
||||||
|
```
|
||||||
|
Returns `true` if and only if `o` contains element equal to `e`. Equivalent to `Option.match(false, x => x == e, o)`.
|
||||||
|
|
||||||
|
|
||||||
### on_elem
|
### on_elem
|
||||||
```
|
```
|
||||||
Option.on_elem(o : option('a), f : 'a => unit) : unit
|
Option.on_elem(o : option('a), f : 'a => unit) : unit
|
||||||
|
@ -15,10 +15,14 @@ namespace List =
|
|||||||
_::t => Some(t)
|
_::t => Some(t)
|
||||||
|
|
||||||
function last(l : list('a)) : option('a) = switch(l)
|
function last(l : list('a)) : option('a) = switch(l)
|
||||||
[] => None
|
[] => None
|
||||||
[x] => Some(x)
|
[x] => Some(x)
|
||||||
_::t => last(t)
|
_::t => last(t)
|
||||||
|
|
||||||
|
function contains(e : 'a, l : list('a)) = switch(l)
|
||||||
|
[] => false
|
||||||
|
h::t => h == e || contains(e, t)
|
||||||
|
|
||||||
/** Finds first element of `l` fulfilling predicate `p` as `Some` or `None`
|
/** Finds first element of `l` fulfilling predicate `p` as `Some` or `None`
|
||||||
* if no such element exists.
|
* if no such element exists.
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +26,10 @@ namespace Option =
|
|||||||
None => abort("Forced None value")
|
None => abort("Forced None value")
|
||||||
Some(x) => x
|
Some(x) => x
|
||||||
|
|
||||||
|
function contains(e : 'a, o : option('a)) = switch(o)
|
||||||
|
None => false
|
||||||
|
Some(x) => x == e
|
||||||
|
|
||||||
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
|
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
|
||||||
|
|
||||||
function map(f : 'a => 'b, o : option('a)) : option('b) = switch(o)
|
function map(f : 'a => 'b, o : option('a)) : option('b) = switch(o)
|
||||||
|
@ -39,7 +39,7 @@ simple_compile_test_() ->
|
|||||||
error(ErrBin)
|
error(ErrBin)
|
||||||
end
|
end
|
||||||
end} || ContractName <- compilable_contracts(), Backend <- [aevm, fate],
|
end} || ContractName <- compilable_contracts(), Backend <- [aevm, fate],
|
||||||
not lists:member(ContractName, not_yet_compilable(Backend))] ++
|
not lists:member(ContractName, not_compilable_on(Backend))] ++
|
||||||
[ {"Test file not found error",
|
[ {"Test file not found error",
|
||||||
fun() ->
|
fun() ->
|
||||||
{error, Errors} = aeso_compiler:file("does_not_exist.aes"),
|
{error, Errors} = aeso_compiler:file("does_not_exist.aes"),
|
||||||
@ -168,8 +168,11 @@ compilable_contracts() ->
|
|||||||
"lhs_matching"
|
"lhs_matching"
|
||||||
].
|
].
|
||||||
|
|
||||||
not_yet_compilable(fate) -> [];
|
not_compilable_on(fate) -> [];
|
||||||
not_yet_compilable(aevm) -> [].
|
not_compilable_on(aevm) ->
|
||||||
|
["stdlib_include",
|
||||||
|
"manual_stdlib_include"
|
||||||
|
].
|
||||||
|
|
||||||
%% Contracts that should produce type errors
|
%% Contracts that should produce type errors
|
||||||
|
|
||||||
@ -316,8 +319,8 @@ failing_contracts() ->
|
|||||||
" x : int\n"
|
" x : int\n"
|
||||||
"against the expected type\n"
|
"against the expected type\n"
|
||||||
" string">>,
|
" string">>,
|
||||||
<<?Pos(14, 24)
|
<<?Pos(14, 35)
|
||||||
"No record type with fields y, z (at line 14, column 24)">>,
|
"No record type with fields z, y (at line 14, column 35)">>,
|
||||||
<<?Pos(15, 26)
|
<<?Pos(15, 26)
|
||||||
"The field z is missing when constructing an element of type r2 (at line 15, column 26)">>,
|
"The field z is missing when constructing an element of type r2 (at line 15, column 26)">>,
|
||||||
<<?Pos(15, 24)
|
<<?Pos(15, 24)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user