Size-tf: creating normal int, double, etc.?

When using the dimensional-tf package, is it possible to work with "normal" Num instances (ie Int , Double , Integer ) without using the one block?

For example, this code does not enter validation (in ghci):

 {-# LANGUAGE NoMonomorphismRestriction #-} import Numeric.Units.Dimensional.TF.Prelude import qualified Prelude as P fourpi = 4 * pi 

but this code does:

 {-# LANGUAGE NoMonomorphismRestriction #-} import Numeric.Units.Dimensional.TF.Prelude import qualified Prelude as P fourpi = (4 *~ one) * (pi *~ one) 

Note: let me know if dimensional should be used instead of dimensional-tf .

+4
source share
1 answer

The dimensional (and dimensional-tf ) package hides operators from Num and Fractional and defines operators with the same name, but different types. These operators do not work with unvarnished number types.

So,

 {-# LANGUAGE NoMonomorphismRestriction #-} import Numeric.Units.Dimensional.TF.Prelude import qualified Prelude as P 

you can't just write

 fourpi = 4 * pi 

since (*) :: Num a => Dimensional vda -> Dimensional vd' a -> Dimensional v (Mul d d') a then, and there are no Num instances for dimensional types (cannot be, since the product of two-dimensional types is usually has a different dimension), so 4 and pi cannot be interpreted as values ​​of the dimensional type.

However you can write

 fourpi = 4 P.* P.pi 

etc., qualified versions of operators from Num are still available.

+4
source

All Articles