1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 13:21:59 +03:00

:note: Abstract/Number.hs.

This commit is contained in:
Patrick Thomson 2020-01-27 10:53:13 -05:00
parent ae98033e1d
commit 87be2f7e8b

View File

@ -1,4 +1,8 @@
{-# LANGUAGE GADTs, StandaloneDeriving, RankNTypes, TypeApplications #-} {-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
module Data.Abstract.Number module Data.Abstract.Number
( Number (..) ( Number (..)
@ -9,10 +13,10 @@ module Data.Abstract.Number
, liftedFloorDiv , liftedFloorDiv
) where ) where
import Data.Scientific import Data.Function (on)
import Data.Scientific
import Prelude hiding (Integer)
import qualified Prelude import qualified Prelude
import Prelude hiding (Integer)
import Prologue
-- | A generalized number type that unifies all interpretable numeric types. -- | A generalized number type that unifies all interpretable numeric types.
-- This is a GADT, so you can specialize the 'a' parameter and be confident -- This is a GADT, so you can specialize the 'a' parameter and be confident
@ -34,13 +38,13 @@ deriving instance Eq a => Eq (Number a)
instance Show (Number a) where instance Show (Number a) where
show (Integer i) = show i show (Integer i) = show i
show (Ratio r) = show r show (Ratio r) = show r
show (Decimal d) = show d show (Decimal d) = show d
-- | Every 'Number' can be coerced to a 'Scientific'. Used in the 'Ord' instance. -- | Every 'Number' can be coerced to a 'Scientific'. Used in the 'Ord' instance.
toScientific :: Number a -> Scientific toScientific :: Number a -> Scientific
toScientific (Integer i) = fromInteger i toScientific (Integer i) = fromInteger i
toScientific (Ratio r) = fromRational r toScientific (Ratio r) = fromRational r
toScientific (Decimal s) = s toScientific (Decimal s) = s
instance Eq a => Ord (Number a) where compare = compare `on` toScientific instance Eq a => Ord (Number a) where compare = compare `on` toScientific