Haskell's arithmetic operations and the constancy of the database of arbitrary / fixed precision numbers

As a newcomer to Haskell (GHC), I ran into the problem of handling data types and arithmetic operations related to a business domain, which include currency / money operations, and I am looking for a solution.

I am developing an application that should interact with the (independent) accounting module (via web services), while at the same time having a (web interface) user interface for ad-hoc data entry, which is stored in a separate database (PostgreSQL).

I come from a C # / F # environment, and System.Decimal covers all the basic needs. Please correct me if I am wrong, but Haskell does not seem to have an integrated (default) data type that could be considered equivalent.

An ideal choice is a data type that offers arbitrary precision arithmetic, or at least something in Decimal128 lines (IEEE 754). The type should support rounding (to the nearest, ties from zero and, if possible, also tied to even) and the following operations: add, subtract, multiply, divide (ideally also the square / root). Conversions between types must also be supported.

From what I managed to find, there are two Haskell modules in Hackage that need to perform calculations exactly - Data.Fixed and Data.Decimal (by the way, is there a way to create custom literals in Haskell - for example, to copy 123.45m from F #?) . At least the last, as far as I can tell (after a quick test), allows most of what I described in the previous paragraph, but when I add DB (PostgreSQL via Persistent / HDBC) and a web framework (YESOD) to things laughter does not look so Persian. Support there seems to be missing.

- , , ( = > = > ) (, , ) ( )?

+5
1

Yesod Database.Persist. newtype wrapping Data.Fixed Int64, :

newtype Dollars = Dollars { unDollars :: Centi } deriving (Eq, Num)

instance PersistField Dollars where
   toPersistValue = PersistInt64 . fromIntegral . fromEnum . unDollars
   fromPersistValue (PersistInt64 c) = Right . Dollars . toEnum . fromIntegral $ c
   fromPersistValue x = Left . Text.pack $ "Expected Int64 counting cents, got: " ++ show x
+2

All Articles