{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Data.Function.FastMemo.Int () where

import Data.Function.FastMemo.Class (Memoizable (..))
import Data.Function.FastMemo.Word ()
import Data.Int
import Data.Word

deriving via IntegralConversion Int Word instance Memoizable Int

deriving via IntegralConversion Int8 Word8 instance Memoizable Int8

deriving via IntegralConversion Int16 Word16 instance Memoizable Int16

deriving via IntegralConversion Int32 Word32 instance Memoizable Int32

deriving via IntegralConversion Int64 Word64 instance Memoizable Int64

newtype IntegralConversion a b = IntegralConversion {IntegralConversion a b -> a
getIntegralConversion :: a}

instance (Integral a, Integral b, Memoizable b) => Memoizable (IntegralConversion a b) where
  memoize :: (IntegralConversion a b -> b) -> IntegralConversion a b -> b
memoize IntegralConversion a b -> b
f =
    (b -> b) -> b -> b
forall a b. Memoizable a => (a -> b) -> a -> b
memoize (IntegralConversion a b -> b
f (IntegralConversion a b -> b)
-> (b -> IntegralConversion a b) -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IntegralConversion a b
forall a b. a -> IntegralConversion a b
IntegralConversion (a -> IntegralConversion a b)
-> (b -> a) -> b -> IntegralConversion a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral)
      (b -> b)
-> (IntegralConversion a b -> b) -> IntegralConversion a b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral :: a -> b)
      (a -> b)
-> (IntegralConversion a b -> a) -> IntegralConversion a b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntegralConversion a b -> a
forall a b. IntegralConversion a b -> a
getIntegralConversion