module Slist.Size
( Size (..)
, sizes
) where
data Size
= Size !Int
| Infinity
deriving (Show, Read, Eq, Ord)
instance Num Size where
(+) :: Size -> Size -> Size
Infinity + _ = Infinity
_ + Infinity = Infinity
(Size x) + (Size y) = Size $ x + y
{-# INLINE (+) #-}
(-) :: Size -> Size -> Size
Infinity - _ = Infinity
_ - Infinity = Infinity
(Size x) - (Size y) = Size (x - y)
{-# INLINE (-) #-}
(*) :: Size -> Size -> Size
Infinity * _ = Infinity
_ * Infinity = Infinity
(Size x) * (Size y) = Size (x * y)
{-# INLINE (*) #-}
abs :: Size -> Size
abs Infinity = Infinity
abs (Size x) = Size $ abs x
{-# INLINE abs #-}
signum :: Size -> Size
signum Infinity = Infinity
signum (Size x) = Size (signum x)
{-# INLINE signum #-}
fromInteger :: Integer -> Size
fromInteger = Size . fromInteger
{-# INLINE fromInteger #-}
instance Bounded Size where
minBound :: Size
minBound = Size 0
maxBound :: Size
maxBound = Infinity
sizes :: Size -> [Size]
sizes (Size n) = map Size [0..n]
sizes Infinity = map Size [0..maxBound] ++ [Infinity]