You can do this in GHC 7.8 using level literals:
{-# LANGUAGE DataKinds, PolyKinds, ScopedTypeVariables #-} module SO26723035 where import GHC.TypeLits import Data.Proxy newtype MNat (n :: Nat) = MakeMNat Int deriving (Eq, Ord, Show) instance KnownNat n => Bounded (MNat n) where minBound = MakeMNat 0 maxBound = MakeMNat . fromInteger $ natVal (Proxy :: Proxy n)
ghci> maxBound :: MNat 5 MakeMNat 5
You can use type synonyms to correct individual types. The rest of your code compiles fine with this polymorphic MNat with mechanical changes. You must add the KnownNat context everywhere and use ScopedTypeVariables in MNat .
Christian conkle
source share