Fix stdlib warnings

This commit is contained in:
Gaith Hallak 2022-01-30 15:02:43 +04:00
parent b3767071a8
commit a3405ee0d2
5 changed files with 25 additions and 35 deletions

View File

@ -7,13 +7,13 @@ namespace BLS12_381 =
record gt = { x1 : fp, x2 : fp, x3 : fp, x4 : fp, x5 : fp, x6 : fp, record gt = { x1 : fp, x2 : fp, x3 : fp, x4 : fp, x5 : fp, x6 : fp,
x7 : fp, x8 : fp, x9 : fp, x10 : fp, x11 : fp, x12 : fp } x7 : fp, x8 : fp, x9 : fp, x10 : fp, x11 : fp, x12 : fp }
function pairing_check(xs : list(g1), ys : list(g2)) = function pairing_check(us : list(g1), vs : list(g2)) =
switch((xs, ys)) switch((us, vs))
([], []) => true ([], []) => true
(x :: xs, y :: ys) => pairing_check_(pairing(x, y), xs, ys) (x :: xs, y :: ys) => pairing_check_(pairing(x, y), xs, ys)
function pairing_check_(acc : gt, xs : list(g1), ys : list(g2)) = function pairing_check_(acc : gt, us : list(g1), vs : list(g2)) =
switch((xs, ys)) switch((us, vs))
([], []) => gt_is_one(acc) ([], []) => gt_is_one(acc)
(x :: xs, y :: ys) => (x :: xs, y :: ys) =>
pairing_check_(gt_mul(acc, pairing(x, y)), xs, ys) pairing_check_(gt_mul(acc, pairing(x, y)), xs, ys)

View File

@ -116,16 +116,6 @@ namespace Bitwise =
1 => ubxor__(a / 2, b / 2, val * 2, acc + val) 1 => ubxor__(a / 2, b / 2, val * 2, acc + val)
_ => ubxor__(a / 2, b / 2, val * 2, acc) _ => ubxor__(a / 2, b / 2, val * 2, acc)
// Bitwise combined 'and' and 'not' of second argument for positive integers
// x 'bnand' y = x 'band' ('bnot' y)
// The tricky bit is that after negation the second argument has an infinite number of 1's
// use as many as needed!
//
// NOTE: this function is not symmetric!
private function ubnand(a, b) =
require(a >= 0 && b >= 0, "ubxor is only defined for non-negative integers")
ubnand__(a, b, 1, 0)
private function ubnand_(a, b) = ubnand__(a, b, 1, 0) private function ubnand_(a, b) = ubnand__(a, b, 1, 0)
private function private function

View File

@ -173,7 +173,7 @@ namespace List =
if (n == 0) l if (n == 0) l
else switch(l) else switch(l)
[] => [] [] => []
h::t => drop_(n-1, t) _::t => drop_(n-1, t)
/** Get the longest prefix of a list in which every element /** Get the longest prefix of a list in which every element
* matches predicate `p` * matches predicate `p`
@ -191,7 +191,7 @@ namespace List =
/** Splits list into two lists of elements that respectively /** Splits list into two lists of elements that respectively
* match and don't match predicate `p` * match and don't match predicate `p`
*/ */
function partition(p : 'a => bool, l : list('a)) : (list('a) * list('a)) = switch(l) function partition(p : 'a => bool, lst : list('a)) : (list('a) * list('a)) = switch(lst)
[] => ([], []) [] => ([], [])
h::t => h::t =>
let (l, r) = partition(p, t) let (l, r) = partition(p, t)
@ -313,4 +313,4 @@ namespace List =
function enumerate(l : list('a)) : list(int * 'a) = enumerate_(l, 0) function enumerate(l : list('a)) : list(int * 'a) = enumerate_(l, 0)
private function enumerate_(l : list('a), n : int) : list(int * 'a) = switch(l) private function enumerate_(l : list('a), n : int) : list(int * 'a) = switch(l)
[] => [] [] => []
h::t => (n, h)::enumerate_(t, n + 1) h::t => (n, h)::enumerate_(t, n + 1)

View File

@ -2,8 +2,8 @@ namespace ListInternal =
// -- Flatmap ---------------------------------------------------------------- // -- Flatmap ----------------------------------------------------------------
function flat_map(f : 'a => list('b), xs : list('a)) : list('b) = function flat_map(f : 'a => list('b), lst : list('a)) : list('b) =
switch(xs) switch(lst)
[] => [] [] => []
x :: xs => f(x) ++ flat_map(f, xs) x :: xs => f(x) ++ flat_map(f, xs)

View File

@ -53,21 +53,21 @@ namespace String =
// Converts a decimal ("123", "-253") or a hexadecimal ("0xa2f", "-0xBBB") string // Converts a decimal ("123", "-253") or a hexadecimal ("0xa2f", "-0xBBB") string
// into an integer. If the string doesn't contain a valid number `None` is returned. // into an integer. If the string doesn't contain a valid number `None` is returned.
function to_int(s : string) : option(int) = function to_int(str : string) : option(int) =
let s = StringInternal.to_list(s) let lst = StringInternal.to_list(str)
switch(is_prefix(['-'], s)) switch(is_prefix(['-'], lst))
None => to_int_pos(s) None => to_int_pos(lst)
Some(s) => switch(to_int_pos(s)) Some(s) => switch(to_int_pos(s))
None => None None => None
Some(x) => Some(-x) Some(x) => Some(-x)
// Private helper functions below // Private helper functions below
private function to_int_pos(s : list(char)) = private function to_int_pos(chs : list(char)) =
switch(is_prefix(['0', 'x'], s)) switch(is_prefix(['0', 'x'], chs))
None => None =>
to_int_(s, ch_to_int_10, 0, 10) to_int_(chs, ch_to_int_10, 0, 10)
Some(s) => Some(str) =>
to_int_(s, ch_to_int_16, 0, 16) to_int_(str, ch_to_int_16, 0, 16)
private function private function
tokens_(_, [], acc) = [StringInternal.from_list(List.reverse(acc))] tokens_(_, [], acc) = [StringInternal.from_list(List.reverse(acc))]
@ -84,8 +84,8 @@ namespace String =
contains_(ix, str, substr) = contains_(ix, str, substr) =
switch(is_prefix(substr, str)) switch(is_prefix(substr, str))
None => None =>
let _ :: str = str let _ :: tailstr = str
contains_(ix + 1, str, substr) contains_(ix + 1, tailstr, substr)
Some(_) => Some(_) =>
Some(ix) Some(ix)
@ -101,15 +101,15 @@ namespace String =
to_int_(i :: is, value, x, b) = to_int_(i :: is, value, x, b) =
switch(value(i)) switch(value(i))
None => None None => None
Some(i) => to_int_(is, value, x * b + i, b) Some(n) => to_int_(is, value, x * b + n, b)
private function ch_to_int_10(c) = private function ch_to_int_10(ch) =
let c = Char.to_int(c) let c = Char.to_int(ch)
if(c >= 48 && c =< 57) Some(c - 48) if(c >= 48 && c =< 57) Some(c - 48)
else None else None
private function ch_to_int_16(c) = private function ch_to_int_16(ch) =
let c = Char.to_int(c) let c = Char.to_int(ch)
if(c >= 48 && c =< 57) Some(c - 48) if(c >= 48 && c =< 57) Some(c - 48)
elif(c >= 65 && c =< 70) Some(c - 55) elif(c >= 65 && c =< 70) Some(c - 55)
elif(c >= 97 && c =< 102) Some(c - 87) elif(c >= 97 && c =< 102) Some(c - 87)