haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

Inquiry about Element Instance for Rational Numbers #370

Open nasosev opened 1 year ago

nasosev commented 1 year ago

Hello maintainers of hmatrix,

I'm deeply appreciative of the diligent work that has gone into the development of this library, and I've found it instrumental in my projects.

I'm currently exploring the possibility of working with matrices containing Rational number elements. While delving into the documentation, I noticed that there isn't an Element instance for Rational numbers. The Storable constraint, associated with the Element type class, seems to be a potential obstacle for this due to Rational's underlying representation as pairs of Integer.

I'd love to gather some insights:

  1. Feasibility: Given the Storable constraint on the Element type class, how challenging might it be to introduce an Element instance for Rational numbers? Are we looking at deep architectural challenges, or could it be more of an implementation matter?
  2. Alternative Approaches: If creating such an instance is non-trivial, are there suggested workarounds or patterns that might allow one to achieve similar functionality with Rational numbers within hmatrix?
  3. Contributions: If the library could benefit from adjustments to support this, could you point me towards relevant sections of the codebase? I'm quite keen on exploring this further and, if possible, contributing towards such a feature.

Your insights would be invaluable. Thank you in advance for any direction you can provide.