double-extra (empty) → 0.1.0.0
raw patch · 9 files changed
+215/−0 lines, 9 filesdep +aesondep +basedep +bytestringsetup-changed
Dependencies added: aeson, base, bytestring, cassava, deepseq, double-conversion, rawstring-qm, text
Files
- Data/Double/Extra.hs +15/−0
- Data/Double/Extra/Aeson.hs +31/−0
- Data/Double/Extra/Cassava.hs +17/−0
- Data/Double/Extra/RawString.hs +31/−0
- Data/Double/Extra/Types.hs +31/−0
- LICENSE +30/−0
- README.md +3/−0
- Setup.hs +2/−0
- double-extra.cabal +55/−0
+ Data/Double/Extra.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE CPP #-}+module Data.Double.Extra+ ( module X+ ) where++import Data.Double.Extra.Types as X+import Data.Double.Extra.Aeson as X++#if CASSAVA+import Data.Double.Extra.Cassava as X+#endif++#if RAWSTRING_QM+import Data.Double.Extra.RawString as X+#endif
+ Data/Double/Extra/Aeson.hs view
@@ -0,0 +1,31 @@+module Data.Double.Extra.Aeson where++import Data.Double.Extra.Types+import qualified Data.ByteString.Builder as B+import Data.Aeson (FromJSON(..), ToJSON(..))+import qualified Data.Aeson.Types as AI+import Data.Double.Conversion.ByteString++instance FromJSON (DoubleFixed n) where+ parseJSON = coerce . (parseJSON :: AI.Value -> AI.Parser Double)+instance KnownNat n => ToJSON (DoubleFixed n) where+ toJSON = (toJSON :: Double -> AI.Value) . coerce+ toEncoding x = AI.unsafeToEncoding $ B.byteString . toFixed (fromIntegral (natVal x)) $ coerce x++instance FromJSON (DoublePrecision n) where+ parseJSON = coerce . (parseJSON :: AI.Value -> AI.Parser Double)+instance KnownNat n => ToJSON (DoublePrecision n) where+ toJSON = (toJSON :: Double -> AI.Value) . coerce+ toEncoding x = AI.unsafeToEncoding $ B.byteString . toPrecision (fromIntegral (natVal x)) $ coerce x++instance FromJSON (DoubleExponential n) where+ parseJSON = coerce . (parseJSON :: AI.Value -> AI.Parser Double)+instance KnownNat n => ToJSON (DoubleExponential n) where+ toJSON = (toJSON :: Double -> AI.Value) . coerce+ toEncoding x = AI.unsafeToEncoding $ B.byteString . toExponential (fromIntegral (natVal x)) $ coerce x++instance FromJSON DoubleShortest where+ parseJSON = coerce . (parseJSON :: AI.Value -> AI.Parser Double)+instance ToJSON DoubleShortest where+ toJSON = (toJSON :: Double -> AI.Value) . coerce+ toEncoding = AI.unsafeToEncoding . B.byteString . toShortest . coerce
+ Data/Double/Extra/Cassava.hs view
@@ -0,0 +1,17 @@+module Data.Double.Extra.Cassava where++import Data.Double.Extra.Types+import Data.Double.Conversion.ByteString+import qualified Data.Csv as CSV++instance KnownNat n => CSV.ToField (DoubleFixed n) where+ toField x = toFixed (fromIntegral (natVal x)) $ coerce x++instance KnownNat n => CSV.ToField (DoublePrecision n) where+ toField x = toPrecision (fromIntegral (natVal x)) $ coerce x++instance KnownNat n => CSV.ToField (DoubleExponential n) where+ toField x = toExponential (fromIntegral (natVal x)) $ coerce x++instance CSV.ToField DoubleShortest where+ toField = coerce toShortest
+ Data/Double/Extra/RawString.hs view
@@ -0,0 +1,31 @@+module Data.Double.Extra.RawString where++import Data.Text.ToText+import Data.Text.ToTextBuilder+import Data.Double.Extra.Types+import Data.Double.Conversion.Text+import Data.Text.Lazy.Builder as B+import qualified Data.Text.Lazy as TL++instance KnownNat n => ToTextBuilder (DoubleFixed n) where+ toTextBuilder x = B.fromText . toFixed (fromIntegral (natVal x)) $ coerce x+instance KnownNat n => ToTextBuilder (DoublePrecision n) where+ toTextBuilder x = B.fromText . toPrecision (fromIntegral (natVal x)) $ coerce x+instance KnownNat n => ToTextBuilder (DoubleExponential n) where+ toTextBuilder x = B.fromText . toExponential (fromIntegral (natVal x)) $ coerce x+instance ToTextBuilder DoubleShortest where+ toTextBuilder = B.fromText . toShortest . coerce+++instance KnownNat n => ToText (DoubleFixed n) where+ toText x = toFixed (fromIntegral (natVal x)) $ coerce x+ toLazyText = TL.fromStrict . toText+instance KnownNat n => ToText (DoublePrecision n) where+ toText x = toPrecision (fromIntegral (natVal x)) $ coerce x+ toLazyText = TL.fromStrict . toText+instance KnownNat n => ToText (DoubleExponential n) where+ toText x = toExponential (fromIntegral (natVal x)) $ coerce x+ toLazyText = TL.fromStrict . toText+instance ToText DoubleShortest where+ toText = toShortest . coerce+ toLazyText = TL.fromStrict . toText
+ Data/Double/Extra/Types.hs view
@@ -0,0 +1,31 @@+module Data.Double.Extra.Types+ ( DoublePrecision(..)+ , DoubleExponential(..)+ , DoubleFixed(..)+ , DoubleShortest(..)+ , module X+ ) where++import Control.DeepSeq (NFData)+import GHC.TypeLits as X+import Data.Coerce as X+import GHC.Generics++newtype DoublePrecision (i :: Nat) = DoublePrecision Double+ deriving (Eq,Ord,Show,Read,Generic,NFData,Num)++newtype DoubleExponential (i :: Nat) = DoubleExponential Double+ deriving (Eq,Ord,Show,Read,Generic,NFData,Num)++newtype DoubleFixed (i :: Nat) = DoubleFixed Double+ deriving (Eq,Ord,Show,Read,Generic,NFData,Num)++newtype DoubleShortest = DoubleShortest Double+ deriving (Eq,Ord,Show,Read,Generic,NFData,Num)++{-+DoublePrecision (i :: Nat)+DoubleExponential (i :: Nat)+DoubleFixed (i :: Nat)+DoubleShortest+-}
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Marcin Tolysz (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Marcin Tolysz nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# double-extra+Missing presentations for Double numbers (fixed, scientific etc.)+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ double-extra.cabal view
@@ -0,0 +1,55 @@+name: double-extra+version: 0.1.0.0+synopsis: Missing presentations for Double numbers (fixed, scientific etc.)+description: Please see README.md+homepage: https://github.com/tolysz/double-extra#readme+license: BSD3+license-file: LICENSE+author: Marcin Tolysz+maintainer: tolysz@gmail.com+copyright: 2017(c) Marcin Tolysz+category: Library+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10++Flag cassava+ Description: Build the example server+ Default: True++Flag rawstring-qm+ Description: Build the example server+ Default: True++library+ exposed-modules:+ Data.Double.Extra+ other-modules:+ Data.Double.Extra.Aeson+ Data.Double.Extra.Types++ build-depends: base >= 4.7 && < 5+ , double-conversion == 2.0.2.0+ , aeson+ , bytestring+ , deepseq+ if flag(cassava)+ build-depends: cassava+ other-modules: Data.Double.Extra.Cassava+ cpp-options: -DCASSAVA++ if flag(rawstring-qm)+ build-depends: rawstring-qm, text+ other-modules: Data.Double.Extra.RawString+ cpp-options: -DRAWSTRING_QM++ default-language: Haskell2010+ default-extensions:+ KindSignatures+ DataKinds+ DeriveGeneric+ GeneralizedNewtypeDeriving++source-repository head+ type: git+ location: https://github.com/tolysz/double-extra