{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wno-identities #-}
module Graphics.Implicit.IntegralUtil (ℕ, toℕ, fromℕ) where
import Prelude (Integral, Integer, Int, Show, Read, Eq, Ord, Num, Enum, Integral, Real, ($), fromIntegral, (.))
import Graphics.Implicit.FastIntUtil (Fastℕ(Fastℕ))
class (Integral n) => N n where
fromℕ :: ℕ -> n
toℕ :: n -> ℕ
instance N Integer where
fromℕ (ℕ a) = a
{-# INLINABLE fromℕ #-}
toℕ = ℕ
{-# INLINABLE toℕ #-}
instance N Fastℕ where
fromℕ (ℕ a) = Fastℕ $ fromIntegral a
{-# INLINABLE fromℕ #-}
toℕ = ℕ . fromIntegral
{-# INLINABLE toℕ #-}
instance N Int where
fromℕ (ℕ a) = fromIntegral a
{-# INLINABLE fromℕ #-}
toℕ = ℕ . fromIntegral
{-# INLINABLE toℕ #-}
newtype ℕ = ℕ Integer
deriving (Show, Read, Eq, Ord, Num, Enum, Integral, Real)