units 2.2 → 2.2.1
raw patch · 6 files changed
+44/−9 lines, 6 files
Files
- CHANGES.md +10/−0
- Data/Metrology.hs +1/−1
- Data/Metrology/Qu.hs +7/−0
- Data/Metrology/TH.hs +14/−4
- Tests/Compile/EvalType.hs +4/−2
- units.cabal +8/−2
CHANGES.md view
@@ -1,3 +1,13 @@+Release notes for `units`+=========================++Version 2.2.1+-------------++* Compatibility with GHC 7.10.++* Added `AdditiveGroup` and `VectorSpace` instances for `Qu`.+ Version 2.2 -----------
Data/Metrology.hs view
@@ -33,7 +33,7 @@ -- The units package is a framework for strongly-typed dimensional analysis. -- This haddock documentation is generally /not/ enough to be able to use this -- package effectively. Please see the readme at--- <http://www.cis.upenn.edu/~eir/packages/units/README.html>.+-- <https://github.com/goldfirere/units/blob/master/README.md>. -- -- Some of the types below refer to declarations that are not exported and -- not documented here. This is because Haddock does not allow finely-tuned
Data/Metrology/Qu.hs view
@@ -22,6 +22,8 @@ import Data.Metrology.Z import Data.Metrology.LCSU +import Data.VectorSpace+ ------------------------------------------------------------- --- Internal ------------------------------------------------ -------------------------------------------------------------@@ -206,6 +208,11 @@ deriving instance Eq n => Eq (Qu d l n) deriving instance Ord n => Ord (Qu d l n)++deriving instance AdditiveGroup n => AdditiveGroup (Qu d l n)+instance VectorSpace n => VectorSpace (Qu d l n) where+ type Scalar (Qu d l n) = Scalar n+ a *^ (Qu b) = Qu (a *^ b) ------------------------------------------------------------- --- Instances for dimensionless quantities ------------------
Data/Metrology/TH.hs view
@@ -11,7 +11,7 @@ -- @units@ a little more convenient. ----------------------------------------------------------------------------- -{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TemplateHaskell, CPP #-} {-# OPTIONS_HADDOCK prune #-} module Data.Metrology.TH (@@ -45,6 +45,11 @@ -- more polymorphic types. (If it doesn't work, not all of the type families -- will be evaluated, and the instance declaration will fail. This function -- should never cause /incorrect/ behavior.)+--+-- Note: Under GHC 7.10 and later, this function works only for base types+-- like @Length@, not compound types like @Volume@ or @Velocity@. See+-- <https://github.com/goldfirere/units/issues/34> for more info and a+-- workaround. evalType :: Q Type -> Q Type evalType qty = do ty <- qty@@ -193,8 +198,8 @@ n = VarT n_name const_name = mkName name const_type = ForallT [PlainTV lcsu_name, PlainTV n_name]- [ ClassP ''Fractional [n]- , ClassP ''CompatibleUnit [lcsu, unit_type] ] $+ [ mkClassP ''Fractional [n]+ , mkClassP ''CompatibleUnit [lcsu, unit_type] ] $ ConT ''MkQu_ULN `AppT` unit_type `AppT` lcsu `AppT` n ty_sig = SigD const_name const_type dec = ValD (VarP const_name) (NormalB $@@ -202,4 +207,9 @@ `AppE` SigE (VarE 'undefined) unit_type) [] return [ty_sig, dec]- + where+#if __GLASGOW_HASKELL__ < 709+ mkClassP = ClassP+#else+ mkClassP n tys = foldl AppT (ConT n) tys+#endif
Tests/Compile/EvalType.hs view
@@ -2,7 +2,8 @@ Copyright (c) 2014 Richard Eisenberg -} -{-# LANGUAGE TemplateHaskell, FlexibleInstances, DataKinds, CPP #-}+{-# LANGUAGE TemplateHaskell, FlexibleInstances, DataKinds, CPP,+ KindSignatures #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Tests.Compile.EvalType where@@ -14,7 +15,8 @@ instance Show $(evalType [t| Length |]) where show x = x `showIn` Meter -#if MIN_VERSION_th_desugar(1,5,0)+#if MIN_VERSION_th_desugar(1,5,0) && __GLASGOW_HASKELL__ < 709+ -- See #34 instance Show $(evalType [t| Volume |]) where show x = x `showIn` Liter #endif
units.cabal view
@@ -1,5 +1,5 @@ name: units-version: 2.2+version: 2.2.1 cabal-version: >= 1.10 synopsis: A domain-specific type system for dimensional analysis homepage: https://github.com/goldfirere/units@@ -42,10 +42,14 @@ source-repository this type: git location: https://github.com/goldfirere/units.git- tag: v2.2+ tag: v2.2.1 library ghc-options: -Wall++ if impl(ghc >= 7.10)+ ghc-options: -fno-warn-unticked-promoted-constructors+ build-depends: base >= 4.7 && < 5 , th-desugar >= 1.4.2 , singletons >= 0.9 && < 2@@ -105,6 +109,8 @@ -- optimize compile time, not runtime! ghc-options: -O0 -Wall -main-is Tests.Main+ if impl(ghc >= 7.10)+ ghc-options: -fno-warn-unticked-promoted-constructors -- GHC 7.10 requires this in more places, and I don't feel like ferreting out exactly -- where.