Int * nat multiplication and unhelpful compiler error
It's not clear if int * nat
or nat * int
multiplication is supported but if not, it's not clear why not... int * nat -> int
as in Michelson is a reasonable operation.
This leads me to this program:
type fraction =
{
num : int,
den : nat
};
type storage = fraction;
type parameter = unit;
let twopow_aux = (base : nat, accu : nat, n : nat) =>
if (n > 0n) {
if (n mod 2n == 1n) {
continue((base * base, accu * base, n / 2n));
} else {
continue((base * base, accu, n / 2n));
};
} else {
stop((base, accu, n));
};
let twopow = (n : nat) : nat => {
let (_, x, _) = Loop.fold_while(twopow_aux, (2n, 1n, n));
x
};
let exp = (x : fraction) : fraction => {
let r : int = 1649 * x.num;
let s : nat = 1143n * x.den;
let ab = {
num: r / int(s), den: r mod s
};
let (i, f) =
if (2 * ab.den <= s) {
(ab.num, {num: ab.den, den: 1649n * x.den});
}
else {
(ab.num + 1, {num: ab.den - s, den: 1649n * x.den});
};
let tp = twopow(i) ;
let num : int = (f.num * f.num + 6 * f.num * f.den + 12 * f.den * f.den) * tp.num;
let den : int = (f.num * f.num - 6 * f.num * f.den + 12 * f.den * f.den) * tp.den;
if (den < 0)
{
{num:-num, den:abs(den)};
} else {
{num:num, den:den};
};
};
let main = (p : parameter, s : storage) =>
{
let r = exp(s);
([]: list(operation), r)
};
Using the compiler
Rolling release
Hash: c5d1b74c00e0e9e8033f2727d51df0b64c51f647
Date: 2019-12-29 01:24:22 +0000
CI job id: 390268229
It tells me
ligo: in file "exp.religo", line 28, character 10 to line 50, character 5. Multiplying with wrong types
The error unhelpfully covers 22 lines of code instead of identifying the problematic multiplication.