BiobaseTypes-0.0.2.1: Biobase/Types/Partition.hs
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Biobase.Types.Partition where
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import Data.Primitive.Types
import Biobase.Types.Ring
-- | Some default instances. Left out the Num one, so that you have to
-- explicitly instanciate if you want to go around the Ring structure.
newtype Partition = Partition {unPartition :: Double}
deriving (Show, Read, Eq, Ord)
-- | Ring operations over Partition values.
instance Ring Partition where
(Partition a) .+. (Partition b) = Partition $ a + b
{-# INLINE (.+.) #-}
(Partition a) .*. (Partition b) = Partition $ a * b
{-# INLINE (.*.) #-}
(Partition a) .^. k = Partition $ a ^ k
{-# INLINE (.^.) #-}
(Partition a) .^^. k = error ".^^. not defined for Partition" -- Partition $ a ^^ k
{-# INLINE (.^^.) #-}
neg (Partition a) = Partition $ negate a
{-# INLINE neg #-}
one = Partition 1
{-# INLINE one #-}
zero = Partition 0
{-# INLINE zero #-}
isZero (Partition a) = a == 0 -- TODO use some epsilon?
{-# INLINE isZero #-}
-- * Vector instances.
deriving instance VGM.MVector VU.MVector Partition
deriving instance VG.Vector VU.Vector Partition
deriving instance VU.Unbox Partition
deriving instance Prim Partition