
* Simon Marlow:
We did originally look at targetting the mpn API, but decided against it for the reasons alluded to above - the mpz layer has quite a lot of stuff in it that you would need to replicate. For instance, when you start doing an operation some calculation has to be done to figure out how much memory to allocate for the result.
Sure, and you have to do sign handling. The advantage is that you could use a convenient encoding for length and sign, or deal with carry/borrow in a flexible manner (i.e., stealing another word from the allocation buffer). It's not exactly trivial, but the effort may be worth it.
And be extra careful, because the GMP code is GPL, so our replacement for the mpz bits would probably end up being GPL too.
Actually, it's LGPL, and interesting bits are part of libc under an even more permissive license.