GMP notes ========= need ---- canonical place for high-level GMP types (mpz, mpq, mpf, gmp_randstate) (low-level types (limb type, etc) are exposed by 'integer-gmp') helpers for FFI to high-level GMP code (whether in gmp or 3rd-party libraries) (users of low-level GMP probably don't need much help) want ---- fast BigFloat type ("There are no reallocations during a calculation, only in a change of precision with mpf_set_prec." ) later ----- BigFloat Num instances (with type-level precision ala 'rounded') FFI helper sketch ----------------- appropriate use of safe vs unsafe ffi can't be decided by a binding library.. > peekInteger :: mpz_srcptr_t -> IO Integer straightforward enough? > withIntegerSrc :: Integer -> (mpz_srcptr_t -> IO r) -> IO r for safe foreign call: alloca struct + limbs and copy data? > unsafeWithIntegerSrc :: Integer -> (mpz_srcptr_t -> IO r) -> IO r for unsafe foreign call: alloca struct is it possible and safe to reuse Integer limb array (if it has one)? > pokeInteger :: mpz_ptr_t -> Integer -> IO () > pokeInteger p i = unsafeWithIntegerSrc i $ mpz_set p straightforward, assumes mpz_ptr_t already init'd this mpz_set is foreign imported unsafe > peekRational :: mpq_srcptr_t -> IO Rational could return a pair of Integer in case the mpq isn't canonical? > withRationalSrc :: Rational -> (mpq_srcptr_t -> IO r) -> IO r > unsafeWithRationalSrc :: Rational -> (mpq_srcptr_t -> IO r) -> IO r > pokeRational :: mpq_ptr_t -> Rational -> IO () as Integer versions similarly for BigFloat BigFloat primops ---------------- > addBigFloat :: BigFloat -> BigFloat -> prec -> BigFloat ie, specify output precision explicitly instead of guessing from input > setPrecBigFloat :: BigFloat -> prec -> BigFloat immutability means limb array could be reused if prec is smaller?