This manual documents the planned v0.5.0 API of Luna-Flow/luna-generic.
luna-generic provides general algebraic traits and default numeric instances for Luna projects.
The current release candidate centers on three changes:
FromNatandFromIntegerprovide conversion operations; exact preservation requires a separate law certificate.Integralis ℤ or a quotient ℤ/2^k, andnormalizemust be a section of its canonical map.lift_toandSectionkeep the choice of a representative apart from homomorphisms.
moon add Luna-Flow/luna-generic@0.4.0Then import "Luna-Flow/luna-generic" in your moon.pkg. The package needs
the MoonBit toolchain 0.10 or later (moonc ≥ 0.10).
The repository is one MoonBit package at src, documented as core. Its
certificate subsystem, Hom and Section, has its own pages as hom.
| Part | Tutorial | API | Design |
|---|---|---|---|
core: traits, conversions, instances |
tutorial | API | design |
hom: homomorphisms and sections |
tutorial | API | design |
AddMonoid,MulMonoidAddGroup,MulGroupSemiring,Ring,Fieldexact structures with explicit Law certificatesAddMonoidOps,SemiringOps,RingOps,FieldOps,NumOpsoperation bundlesFromNat,FromIntegerIntegral,NatRoundedArithmeticfor rounded floating operations- Deprecated:
NatHomomorphism,IntegralHomomorphism
- Operations:
One,Zero,Inverse,Conjugate - Default numeric types:
Int,Int16,Int64,UInt,UInt16,UInt64,BigInt,Float,Double
Integralcovers signed integers, unsigned integers, andBigIntNatcovers the integral types with non-negative representatives:UInt,UInt16, andUInt64- Fixed-width integers are ℤ/2^k;
FromInteger::from_integerreduces modulo 2^k Integral::normalizepicks the representative of a value as aBigInt;IntegralThrecords the round-trip law- Unsigned integer instances stop at
Semiring
FromInteger::from_integerconverts out ofBigInt: exact forBigInt, modular for fixed-width integers, rounded forFloatandDoublelift_to(x)lifts to the representative and maps it into the target; it is a function, not a homomorphismNatHomomorphism::from_natandIntegralHomomorphism::from_integralare deprecated in favour ofFromNat,FromIntegerandlift_to
Hom[S, A, B]: a certificate for maps preservingS, bound to source and target runtime Models; checked composition returnsModelMismatchSection[S, Q, A]: a certificate that a lift picks one representative per class of a quotient;Section::of_integralis the canonical one for integral types- Signature tags:
AddMonoidSig,MulMonoidSig,AddGroupSig,SemiringSig,RingSig - Algebra dictionaries
Algebra[S, A], operationsOp[A], the product typeProd[A, B]and reduct witnessesReduct[S, T] Hom::check/Hom::check_bytest the homomorphism laws on samples with strict, lax or approximate strengthHom::check_models/Hom::check_models_byadd exact runtime Model identity checks to finite diagnostics- See the hom API, tutorial and design
The core tutorial writes small generic algorithms against these traits. The core API lists every exported trait and instance, and the core design explains why the hierarchy and the conversions are shaped this way.
- New to the package: read the core tutorial, then the hom tutorial.
- Using it in a library: keep the core API and the hom API at hand; each trait lists the laws an instance must satisfy.
- Contributing: read both design pages, core and hom, before changing a trait or adding an inference rule.
Recommended release checks:
moon check
moon test