So I thought I would fix that Gmp.mpz(3)%2 has the type mixed. My first quick and dirty fix was to update the type of `% a bit by adding
tFunc(tObjIs_GMP_MPZ tInt, tObjIs_GMP_MPZ)
Yes, it ignores the int%mpz and mpz%mpz permutations, but it's a start. Not the right one apparently, as I got the following warning when trying it out on Crypto.Random.
The code
Gmp.mpz random(int top) { return Gmp.mpz(rnd_func( (int)ceil(Math.log2(top)) ), 256) % top; }
generates
Warning: Wong return type. Warning: Expected: { mpz = object(implements _static_modules.Gmp()->mpz) }. Warning: Got : object(is _static_modules.Gmp()->mpz) | mixed.
Why is there a "| mixed" in this type? Is this at all the correct approach? Can we get nicer names than _static_modules.Gmp()->mpz?
So I thought I would fix that Gmp.mpz(3)%2 has the type mixed. My first quick and dirty fix was to update the type of `% a bit by adding
tFunc(tObjIs_GMP_MPZ tInt, tObjIs_GMP_MPZ)
Yes, it ignores the int%mpz and mpz%mpz permutations, but it's a start. Not the right one apparently, as I got the following warning when trying it out on Crypto.Random.
The code
Gmp.mpz random(int top) { return Gmp.mpz(rnd_func( (int)ceil(Math.log2(top)) ), 256) % top; }
generates
Warning: Wong return type. Warning: Expected: { mpz = object(implements _static_modules.Gmp()->mpz) }. Warning: Got : object(is _static_modules.Gmp()->mpz) | mixed.
Why is there a "| mixed" in this type?
You probably need to add a tIfNot (or modifying the existing) for the generic case so that it doesn't match.
Is this at all the correct approach?
Looks like it.
A nicer approach would of course be to add support for LFUN-expansions to the type system.
Can we get nicer names than _static_modules.Gmp()->mpz?
That's just a question of modifying the master.
Warning: Wong return type. Warning: Expected: { mpz = object(implements _static_modules.Gmp()->mpz) }. Warning: Got : object(is _static_modules.Gmp()->mpz) | mixed.
Why is there a "| mixed" in this type?
You probably need to add a tIfNot (or modifying the existing) for the generic case so that it doesn't match.
I don't think I understand how this works. I thought tIfNot(A,B) meant that if A doesn't match, attempt to match B. That would mean that the return value of A is irrelevent, and tMix could never be the result, as B always results in tFlt.
Warning: Wong return type. Warning: Expected: { mpz = object(implements _static_modules.Gmp()->mpz) }. Warning: Got : object(is _static_modules.Gmp()->mpz) | mixed.
Why is there a "| mixed" in this type?
You probably need to add a tIfNot (or modifying the existing) for the generic case so that it doesn't match.
I don't think I understand how this works. I thought tIfNot(A,B) meant that if A doesn't match, attempt to match B. That would mean that the return value of A is irrelevent, and tMix could never be the result, as B always results in tFlt.
What you've missed is probably that typical efuns have types structured like:
tOr(tFunc(...), tFunc(...), tFunc(...), // Special cases. tIfNot(tFunc(tNot(...):tZero), // Not any of the above. tFunc(tMixed:tMixed))) // Fallback case.
If the filter for the fallback case isn't up to date, you will get a tMixed in the result in addition to the result from the special cases.
Well, that is sane, but not how f_mod is defined.
tOr6(tFunc(tMix tObj,tMix), tFunc(tObj tMix,tMix), tFunc(tInt tInt,tInt), tFunc(tStr tInt,tStr), tFunc(tArr(tSetvar(0,tMix)) tInt,tArr(tVar(0))), tIfnot(tFuncV(tNone, tNot(tFlt), tMix), tFunc(tOr(tInt,tFlt) tOr(tInt,tFlt),tFlt))),
if !`%(!float ... : mixed) default to `%(int|float,int|float:float)
pike-devel@lists.lysator.liu.se