packages feed

simple-units 1.0.1.1 → 1.0.2

raw patch · 7 files changed

+94/−58 lines, 7 filesdep +doctestdep +simple-unitsdep ~basedep ~first-class-familiesPVP ok

version bump matches the API change (PVP)

Dependencies added: doctest, simple-units

Dependency ranges changed: base, first-class-families

API changes (from Hackage documentation)

Files

README.md view
@@ -1,24 +1,34 @@ # simple-units-A Haskell library for simple arithmetic with SI units using type-checked dimensional analysis.+A Haskell library for simple arithmetic with SI units using type-checked dimensional analysis.  +[Haddock documentation](groscoe.github.io/simple-units/)++View on [hackage](https://hackage.haskell.org/package/simple-units).++# Example+ ```haskell >>> let newton = kilogram .* meter ./ (second .* second) >>> 23*newton 23.0 kg*m/s^2+ >>> let g = 6.67408e-11 * newton .* (meter .* meter) ./ (kilogram .* kilogram) >>> g -- gravitational constant 6.67408e-11 m^3/kg*s^2+ >>> let gravity m1 m2 r = g .* (m1 * kilogram) .* (m2 * kilogram) ./ (r*meter .* r*meter) >>> let earth_mass = 5.972e24 * kilogram >>> let mars_mass = 6.417e23 * kilogram >>> let earth_radius = 6371 * kilo meter->>> let mars_radius = 3389.5 * kio meter+>>> let mars_radius = 3389.5 * kilo meter >>> let weight_on_earth mass = gravity mass earth_mass earth_radius >>> let weight_on_mars mass = gravity mass mars_mass mars_radius >>> weight_on_earth (80 * kilogram) 785.5719790179963 kg*m/s^2+ >>> weight_on_mars (80 * kilogram) 298.22370259533704 kg*m/s^2+ >>> weight_on_mars 1 ./ weight_on_earth 1 0.3796261966575378 <adimensional> ```
simple-units.cabal view
@@ -1,44 +1,51 @@-cabal-version: 1.12+cabal-version:      1.12+name:               simple-units+version:            1.0.2+license:            MIT+license-file:       LICENSE+copyright:          2019 Gustavo Roscoe+maintainer:         gustavo@gustavoroscoe.com+author:             Gustavo Roscoe+homepage:           https://github.com/groscoe/simple-units#readme+bug-reports:        https://github.com/groscoe/simple-units/issues+synopsis:+    Simple arithmetic with SI units using type-checked dimensional analysis. --- This file has been generated from package.yaml by hpack version 0.31.1.------ see: https://github.com/sol/hpack------ hash: 86a74ca99a7b7499b1457b5625c7a799cd079870b8c85fb735b58c6d7d53728d+description:+    Please see the README on GitHub at <https://github.com/groscoe/simple-units#readme> -name:           simple-units-version:        1.0.1.1-synopsis:       Simple arithmetic with SI units using type-checked dimensional analysis.-description:    Please see the README on GitHub at <https://github.com/groscoe/simple-units#readme>-category:       Numeric, Numerical-homepage:       https://github.com/groscoe/simple-units#readme-bug-reports:    https://github.com/groscoe/simple-units/issues-author:         Gustavo Roscoe-maintainer:     gustavo@gustavoroscoe.com-copyright:      2019 Gustavo Roscoe-license:        MIT-license-file:   LICENSE-build-type:     Simple-extra-source-files:-    README.md+category:           Numeric, Numerical+build-type:         Simple+extra-source-files: README.md  source-repository head-  type: git-  location: https://github.com/groscoe/simple-units+    type:     git+    location: https://github.com/groscoe/simple-units  library-  exposed-modules:-      Units.Simple-  other-modules:-      Units.Simple.Arithmetic-      Units.Simple.Internals-      Units.Simple.Quantity-      Units.Simple.Unit-      Paths_simple_units-  hs-source-dirs:-      src-  ghc-options: -Wall -Wcompat-  build-depends:-      base >=4.9 && <5-    , first-class-families >=0.5 && <0.6-  default-language: Haskell2010+    exposed-modules:  Units.Simple+    hs-source-dirs:   src+    other-modules:+        Units.Simple.Arithmetic+        Units.Simple.Internals+        Units.Simple.Quantity+        Units.Simple.Unit+        Paths_simple_units++    default-language: Haskell2010+    ghc-options:      -Wall -Wcompat+    build-depends:+        base >=4.9 && <5,+        first-class-families >=0.4 && <0.9++test-suite simple-units-test+    type:             exitcode-stdio-1.0+    main-is:          Spec.hs+    hs-source-dirs:   test+    other-modules:    Paths_simple_units+    default-language: Haskell2010+    ghc-options:      -threaded -rtsopts -with-rtsopts=-N+    build-depends:+        base >=4.12.0.0 && <4.13,+        doctest >=0.16.0.1 && <0.17,+        simple-units -any
src/Units/Simple.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-}-{-# LANGUAGE DataKinds #-} module Units.Simple   (-- *The @Quantity@ type     Quantity ()@@ -24,6 +23,7 @@   --   -- Examples:   --+  -- >>> import Units.Simple   -- >>> 273.0*kelvin -- unitary form   -- 273.0 K   -- >>> kelvin' 273.0 -- function form@@ -111,7 +111,7 @@ -- 6 <adimensional> -- >>> adim .+ meter -- <BLANKLINE>--- <interactive>:79:1-13: error:+-- <interactive>... error: --     • Unit mismatch: <adimensional> and m --     • In the expression: adim .+ meter --       In an equation for ‘it’: it = adim .+ meter
src/Units/Simple/Arithmetic.hs view
@@ -1,9 +1,9 @@-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE PolyKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-} module Units.Simple.Arithmetic   ( (.+)   , (.-)@@ -96,11 +96,12 @@ -- -- Examples: --+-- >>> import Units.Simple -- >>> 2 * kilo meter .+ 3 * kilo meter -- 5000 m -- >>> 2*meter .+ 1*second -- <BLANKLINE>--- <interactive>:16:1-19: error:+-- <interactive>... error: --     • Unit mismatch: m and s --     • In the expression: 2 * meter .+ 1 * second --       In an equation for ‘it’: it = 2 * meter .+ 1 * second@@ -113,6 +114,7 @@ -- -- Examples: --+-- >>> import Units.Simple -- >>> let newton = kilogram .* meter ./ (second .* second) -- >>> 10*newton - 2*newton -- 8.0 kg*m/s^2@@ -124,6 +126,7 @@ -- -- Examples: --+-- >>> import Units.Simple -- >>> meter .* meter -- 1 m^2 -- >>> let mps = meter ./ second@@ -146,6 +149,7 @@ -- -- Examples: --+-- >>> import Units.Simple -- >>> let coulomb = second .* ampere -- >>> 20*coulomb ./ 2*second -- 10.0 A
src/Units/Simple/Internals.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-} module Units.Simple.Internals where  import GHC.TypeLits hiding (type (<=))@@ -44,19 +44,23 @@ type instance Eval (a % b) = a `TL.Mod` b  data Show' :: a -> Exp Symbol-type instance Eval (Show' (n :: Nat)) = Eval (Guarded n-  '[ Flip (Fcf.<=) 9 ':= NatToDigit n-   , Otherwise ':= Show' (Eval (n / 10)) <> Show' (Eval (n % 10))-   ])+type instance Eval (Show' (n :: Nat)) =+  Eval (+    If (Eval ((Fcf.<=) n 9))+       (NatToDigit n)+       (Show' (Eval (n / 10)) <> Show' (Eval (n % 10)))+  )   data (<=) :: k -> k -> Exp Bool type instance Eval ((a :: Nat) <= (b :: Nat)) = a <=? b-type instance Eval ((a :: Symbol) <= (b :: Symbol)) = Eval (Guarded (CmpSymbol a b)-  '[ TyEq 'EQ ':= Pure 'True-   , TyEq 'LT ':= Pure 'True-   , Otherwise ':= Pure 'False-   ])+type instance Eval ((a :: Symbol) <= (b :: Symbol)) =+  Eval (+    If (Eval (TyEq 'GT (CmpSymbol a b)))+       (Pure 'False)+       (Pure 'True)+  )+ type instance Eval ('(a, _) <= '(b, _)) = Eval (a <= b)  
src/Units/Simple/Quantity.hs view
@@ -21,6 +21,7 @@ -- -- Examples: --+-- >>> import Units.Simple -- >>> meter -- a unitary quantity associated to meters. -- 1 m -- >>> 2.5*ampere -- constructing through literal arithmetic
+ test/Spec.hs view
@@ -0,0 +1,10 @@+import Test.DocTest++main :: IO ()+main = doctest+  [ "-isrc"+  , "src/Units/Simple.hs"+  , "src/Units/Simple/Arithmetic.hs"+  , "src/Units/Simple/Quantity.hs"+  , "src/Units/Simple/Unit.hs"+  ]