{-# OPTIONS_GHC -Wno-orphans #-}

module Data.Function.FastMemo.Ratio () where

import Data.Function.FastMemo.Class (Memoizable (..))
import Data.Ratio (Ratio, denominator, numerator, (%))

instance (Integral a, Memoizable a) => Memoizable (Ratio a) where
  memoize :: (Ratio a -> b) -> Ratio a -> b
memoize Ratio a -> b
f = ((a, a) -> b) -> (a, a) -> b
forall a b. Memoizable a => (a -> b) -> a -> b
memoize (Ratio a -> b
f (Ratio a -> b) -> ((a, a) -> Ratio a) -> (a, a) -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> Ratio a) -> (a, a) -> Ratio a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry a -> a -> Ratio a
forall a. Integral a => a -> a -> Ratio a
(%)) ((a, a) -> b) -> (Ratio a -> (a, a)) -> Ratio a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Ratio a
x -> (Ratio a -> a
forall a. Ratio a -> a
numerator Ratio a
x, Ratio a -> a
forall a. Ratio a -> a
denominator Ratio a
x))