module Data.Params.Frac
( Frac (..)
, KnownFrac (..)
, fracVal
)
where
import GHC.TypeLits
import Data.Proxy
data Frac = (/) Nat Nat
class KnownFrac (n :: Frac) where
fracSing :: SFrac n
instance (KnownNat a, KnownNat b) => KnownFrac (a/b) where
fracSing = SFrac
(fromIntegral $ natVal (Proxy::Proxy a))
(fromIntegral $ natVal (Proxy::Proxy b))
fracVal :: forall f n proxy. (KnownFrac n, Fractional f) => proxy n -> f
fracVal _ = case fracSing :: SFrac n of
SFrac a b -> fromIntegral a / fromIntegral b
data SFrac (n :: Frac) = SFrac
!Int
!Int