Commit 54addb12 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Clean-up `Data.Fixed`

This gets rid of `-fno-warn-unused-binds` by turning the E* types into
constructor-less data types (as they're used as phantom-types only)

Moreover, this modules uses `AutoDeriveTypeable` so we can drop all those
redundant `deriving (Typeable)` lines as well

Reviewed By: austin, ekmett

Differential Revision: https://phabricator.haskell.org/D385
parent bd6c6f60
{-# LANGUAGE Trustworthy #-} {-# LANGUAGE Trustworthy #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE AutoDeriveTypeable #-}
{-# OPTIONS -Wall -fno-warn-unused-binds #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
...@@ -37,7 +36,6 @@ module Data.Fixed ...@@ -37,7 +36,6 @@ module Data.Fixed
E12,Pico E12,Pico
) where ) where
import Data.Typeable
import Data.Data import Data.Data
import GHC.Read import GHC.Read
import Text.ParserCombinators.ReadPrec import Text.ParserCombinators.ReadPrec
...@@ -61,7 +59,7 @@ mod' n d = n - (fromInteger f) * d where ...@@ -61,7 +59,7 @@ mod' n d = n - (fromInteger f) * d where
-- | The type parameter should be an instance of 'HasResolution'. -- | The type parameter should be an instance of 'HasResolution'.
newtype Fixed a = MkFixed Integer -- ^ /Since: 4.7.0.0/ newtype Fixed a = MkFixed Integer -- ^ /Since: 4.7.0.0/
deriving (Eq,Ord,Typeable) deriving (Eq,Ord)
-- We do this because the automatically derived Data instance requires (Data a) context. -- We do this because the automatically derived Data instance requires (Data a) context.
-- Our manual instance has the more general (Typeable a) context. -- Our manual instance has the more general (Typeable a) context.
...@@ -166,50 +164,43 @@ convertFixed (Number n) ...@@ -166,50 +164,43 @@ convertFixed (Number n)
e = ceiling (logBase 10 (fromInteger r) :: Double) e = ceiling (logBase 10 (fromInteger r) :: Double)
convertFixed _ = pfail convertFixed _ = pfail
data E0 = E0 data E0
deriving (Typeable)
instance HasResolution E0 where instance HasResolution E0 where
resolution _ = 1 resolution _ = 1
-- | resolution of 1, this works the same as Integer -- | resolution of 1, this works the same as Integer
type Uni = Fixed E0 type Uni = Fixed E0
data E1 = E1 data E1
deriving (Typeable)
instance HasResolution E1 where instance HasResolution E1 where
resolution _ = 10 resolution _ = 10
-- | resolution of 10^-1 = .1 -- | resolution of 10^-1 = .1
type Deci = Fixed E1 type Deci = Fixed E1
data E2 = E2 data E2
deriving (Typeable)
instance HasResolution E2 where instance HasResolution E2 where
resolution _ = 100 resolution _ = 100
-- | resolution of 10^-2 = .01, useful for many monetary currencies -- | resolution of 10^-2 = .01, useful for many monetary currencies
type Centi = Fixed E2 type Centi = Fixed E2
data E3 = E3 data E3
deriving (Typeable)
instance HasResolution E3 where instance HasResolution E3 where
resolution _ = 1000 resolution _ = 1000
-- | resolution of 10^-3 = .001 -- | resolution of 10^-3 = .001
type Milli = Fixed E3 type Milli = Fixed E3
data E6 = E6 data E6
deriving (Typeable)
instance HasResolution E6 where instance HasResolution E6 where
resolution _ = 1000000 resolution _ = 1000000
-- | resolution of 10^-6 = .000001 -- | resolution of 10^-6 = .000001
type Micro = Fixed E6 type Micro = Fixed E6
data E9 = E9 data E9
deriving (Typeable)
instance HasResolution E9 where instance HasResolution E9 where
resolution _ = 1000000000 resolution _ = 1000000000
-- | resolution of 10^-9 = .000000001 -- | resolution of 10^-9 = .000000001
type Nano = Fixed E9 type Nano = Fixed E9
data E12 = E12 data E12
deriving (Typeable)
instance HasResolution E12 where instance HasResolution E12 where
resolution _ = 1000000000000 resolution _ = 1000000000000
-- | resolution of 10^-12 = .000000000001 -- | resolution of 10^-12 = .000000000001
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment