daml/compiler/damlc/tests/daml-test-files/Numeric.daml
Martin Huschenbett 0657080bae
Make the type argument order in DA.Numeric explicit (#5817)
All functions in `DA.Numeric` take the scale of the result as their
first type argument. IMO, this is a nice API since you usually only
want to specify the scale of the result since the scale of the
term arguments is most of the times inferred.

However, the current type signatures in `DA.Numeric` bear quite some
risk of being confusing. For instance, in
```haskell
mul : NumericScale n3 => Numeric n1 -> Numeric n2 -> Numeric n3
```
the naming of the type variables suggests that the order of the
type parameters is `n1 n2 n3` when it actually is `n3 n1 n2`.

I consider the knowledge of implicit `forall`s are filled in quite
expert and hence think we should make the order of these type arguments
explicit.

There is also a related mistake in the docs of `shift`. Running a
scenario confirmed that
```haskell
shift @1 @2 1.0 == 10.0
```
Hence, `shift` has multiplied its argument by `10^(2-1)`, which is
`10^(n1 - n2)`.

CHANGELOG_BEGIN
CHANGELOG_END
2020-05-01 22:32:47 +02:00

13 lines
256 B
Haskell

-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @SINCE-LF 1.7
module Numeric where
import DA.Assert
import DA.Numeric
testShift = scenario do
shift @1 @2 1.0 === 10.0
shift @2 @1 1.0 === 0.1