Skip to content

Offer PolyKinded instances for Data.Fixed.HasResolution

Now that we have DataKinds and PolyKinds, how about offering an instance of Data.Fixed.HasResolution for type level natural numbers. For example

instance KnownNat n => HasResolution (n :: Nat) where
    resolution proxy = 10 ^ natVal proxy

or even

instance KnownNat n => HasResolution (n :: Nat) where
    resolution = natVal

This will make it very easy to create fixed-point types on the fly. For example, it would be possible to say 0.3 :: Fixed 17.

The following extensions are required for that to work: DataKinds, PolyKinds, FlexibleInstances, and UndecidableInstances.

Edited by redneb
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information