General algebraic traits and default numeric instances for Luna projects.
This documentation tracks the next breaking release. The previous v0.4.0
surface remains documented in the changelog below.
luna-genericprovides lightweight algebraic traits for additive, multiplicative, ring-like, field-like, and numeric behavior.- The package ships default instances for signed integers, unsigned integers,
BigInt,Float, andDouble. - Conversions between number types separate the explicit exact homomorphism out of ℤ from the choice of a representative for a machine integer.
FromNatandFromIntegerare target-side traits for the unique homomorphisms ℕ ->Selfand ℤ ->Self, taking aBigIntargument.- Operation bundles (
AddMonoidOps,SemiringOps,RingOps,FieldOpsandNumOps) carry capabilities without claiming laws. Exact structure traits return opaqueLawcertificates and require an explicit law method. FloatandDoubleimplement operation bundles andRoundedArithmetic; they do not implement exactSemiring,RingorFieldlaws.Integralnow extendsSemiringOps + FromIntegerand requires explicitIntegralThandIntegerHomomorphismThlaw methods. An integral type is ℤ or a quotient ℤ/2^k, andnormalizepicks a representative.lift_tolifts an integral value to its representative and maps it into anyFromIntegertarget. It is a function, not a homomorphism.Section[S, Q, A]certifies representative lifts of quotient algebras;Section::of_integralis the canonical one for every integral type.Hom::from_integer_exactcertifies the canonical map out of ℤ only with a targetLawfulModel[IntegerHomomorphismTh, SemiringSig, R].NatHomomorphismandIntegralHomomorphismremain deprecated operations.Hom::from_nat,Hom::from_integraland the oldHom::from_integerare removed; useFromNat,FromInteger,Sectionandlift_tofor ordinary conversions.
- Traits: operation bundles (
AddMonoidOps,MulMonoidOps,AddGroupOps,MulGroupOps,SemiringOps,RingOps,FieldOps,NumOps), exact structures (AddMonoid,MulMonoid,AddGroup,MulGroup,Semiring,Ring,CommRing,IntegralDomain,Field,OrderedField),FromNat,FromInteger,Integral,Nat, and the deprecatedNatHomomorphism,IntegralHomomorphism - Certificates and runtime models:
Law,LawfulModel,Model,ModelConstructionError,ModelMismatch, andRoundedArithmetic - Model identities are opaque and compared with
Model::same_identity; model-bound finite checks useHom::check_modelsandHom::check_models_by - Operations:
One,Zero,Inverse,Conjugate - Functions:
lift_to - Generalized homomorphisms:
Hom,Section,Algebra,Op,Prod,Reduct, and the signature tagsAddMonoidSig,MulMonoidSig,AddGroupSig,SemiringSig,RingSig - Default numeric types:
Int,Int16,Int64,UInt,UInt16,UInt64,BigInt,Float,Double
Integralcovers signed and unsigned integers plusBigInt:Int,Int16,Int64,UInt,UInt16,UInt64,BigIntNatcovers the integral types with non-negative representatives:UInt,UInt16,UInt64- Fixed-width integers are ℤ/2^k: their canonical map from ℤ reduces modulo 2^k, and
normalizepicks the representative in the type's range Byteis intentionally excluded from both traits- Unsigned integer instances stop at
SemiringOpsand do not implementAddGroupOps,RingOps, orNumOps
FromInteger::from_integeris exact forBigInt, reduces modulo 2^k for fixed-width integers, and rounds forFloatandDoublelift_to(x)turns a machine integer into another number type without promising to preserve operations; it is a homomorphism only when the target modulus divides the source modulus, as forInt64 -> Int- Use
Section::of_integralandHom::from_integer_exactwhen the exact integer-homomorphism law is available; useFromInteger::from_integeras an ordinary rounded operation otherwise
Comprehensive API documentation is available at mooncakes.io.
The manual is published at lunaflow.cn/en/luna-generic, with Simplified Chinese and Japanese translations. Its English source lives in doc/manual; translations are maintained as gettext catalogs in doc/locale.
The current version is 0.4.0. Release notes for every version are in CHANGELOG.md.
Requires the MoonBit toolchain 0.10 or later. Useful local commands:
moon check
moon testBefore triggering the publish workflow:
- Confirm
moon.modcontains the intended version. - Confirm the README and
doc/manualmatch the exported package surface. - Run
moon checkandmoon test. - Trigger
publish-packageafter the release commit is pushed.