checked-literals
Safe HaskellNone
LanguageGHC2021

CheckedLiterals.Class.Rational

Description

Type classes and helper functions for checked rational literals.

Synopsis

Documentation

class CheckedPositiveRationalLiteral (literalAsString :: Symbol) (numerator :: Nat) (denominator :: Nat) a Source #

Constraint used by the plugin to validate positive rational literals.

Instances

Instances details
CheckedPositiveRationalLiteral str num den Rational Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

CheckedPositiveRationalLiteral str num den Double Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

CheckedPositiveRationalLiteral str num den Float Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 32767) (PositiveSignedRatioNotRepresentable str num den Int16 32768 32767 :: Constraint), Assert (den <=? 32767) (PositiveSignedRatioNotRepresentable str num den Int16 32768 32767 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Int16) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 2147483647) (PositiveSignedRatioNotRepresentable str num den Int32 2147483648 2147483647 :: Constraint), Assert (den <=? 2147483647) (PositiveSignedRatioNotRepresentable str num den Int32 2147483648 2147483647 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Int32) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 9223372036854775807) (PositiveSignedRatioNotRepresentable str num den Int64 9223372036854775808 9223372036854775807 :: Constraint), Assert (den <=? 9223372036854775807) (PositiveSignedRatioNotRepresentable str num den Int64 9223372036854775808 9223372036854775807 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Int64) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 127) (PositiveSignedRatioNotRepresentable str num den Int8 128 127 :: Constraint), Assert (den <=? 127) (PositiveSignedRatioNotRepresentable str num den Int8 128 127 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Int8) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 65535) (PositiveUnsignedRatioNotRepresentable str num den Word16 65535 :: Constraint), Assert (den <=? 65535) (PositiveUnsignedRatioNotRepresentable str num den Word16 65535 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Word16) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 4294967295) (PositiveUnsignedRatioNotRepresentable str num den Word32 4294967295 :: Constraint), Assert (den <=? 4294967295) (PositiveUnsignedRatioNotRepresentable str num den Word32 4294967295 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Word32) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 18446744073709551615) (PositiveUnsignedRatioNotRepresentable str num den Word64 18446744073709551615 :: Constraint), Assert (den <=? 18446744073709551615) (PositiveUnsignedRatioNotRepresentable str num den Word64 18446744073709551615 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Word64) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 255) (PositiveUnsignedRatioNotRepresentable str num den Word8 255 :: Constraint), Assert (den <=? 255) (PositiveUnsignedRatioNotRepresentable str num den Word8 255 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Word8) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

CheckedPositiveRationalLiteral str num den (Ratio Natural) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 9223372036854775807) (PositiveSignedRatioNotRepresentable str num den Int 9223372036854775808 9223372036854775807 :: Constraint), Assert (den <=? 9223372036854775807) (PositiveSignedRatioNotRepresentable str num den Int 9223372036854775808 9223372036854775807 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Int) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 18446744073709551615) (PositiveUnsignedRatioNotRepresentable str num den Word 18446744073709551615 :: Constraint), Assert (den <=? 18446744073709551615) (PositiveUnsignedRatioNotRepresentable str num den Word 18446744073709551615 :: Constraint)) => CheckedPositiveRationalLiteral str num den (Ratio Word) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * res) den <=? 0) (FixedRoundingError str (Fixed res) res :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed res) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1) den <=? 0) (FixedRoundingError str (Fixed E0) 1 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E0) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 10) den <=? 0) (FixedRoundingError str (Fixed E1) 10 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E1) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 100) den <=? 0) (FixedRoundingError str (Fixed E2) 100 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E2) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000) den <=? 0) (FixedRoundingError str (Fixed E3) 1000 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E3) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000000) den <=? 0) (FixedRoundingError str (Fixed E6) 1000000 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E6) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000000000) den <=? 0) (FixedRoundingError str (Fixed E9) 1000000000 :: Constraint) => CheckedPositiveRationalLiteral str num den (Fixed E9) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

type FixedRoundingError (str :: t) (fixedType :: t1) (resolution :: t2) = TypeError (((((((('Text "Literal " ':<>: 'ShowType str) ':<>: 'Text " requires rounding for ") ':<>: 'ShowType fixedType) ':<>: 'Text " (resolution 1/") ':<>: 'ShowType resolution) ':<>: 'Text ").") ':$$: 'Text "The literal cannot be represented exactly without rounding.") ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #

checkedPositiveRationalLiteral :: forall (fixed :: Symbol) (num :: Nat) (den :: Nat) a. CheckedPositiveRationalLiteral fixed num den a => a -> a Source #

Identity helper that attaches a positive rational literal check.

class CheckedNegativeRationalLiteral (str :: Symbol) (numerator :: Nat) (denominator :: Nat) a Source #

Constraint used by the plugin to validate negative rational literals.

Instances

Instances details
CheckedNegativeRationalLiteral str num den Rational Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

CheckedNegativeRationalLiteral str num den Double Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

CheckedNegativeRationalLiteral str num den Float Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 32768) (NegativeSignedRatioNotRepresentable str num den Int16 32768 32767 :: Constraint), Assert (den <=? 32767) (NegativeSignedRatioNotRepresentable str num den Int16 32768 32767 :: Constraint)) => CheckedNegativeRationalLiteral str num den (Ratio Int16) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 2147483648) (NegativeSignedRatioNotRepresentable str num den Int32 2147483648 2147483647 :: Constraint), Assert (den <=? 2147483647) (NegativeSignedRatioNotRepresentable str num den Int32 2147483648 2147483647 :: Constraint)) => CheckedNegativeRationalLiteral str num den (Ratio Int32) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 9223372036854775808) (NegativeSignedRatioNotRepresentable str num den Int64 9223372036854775808 9223372036854775807 :: Constraint), Assert (den <=? 9223372036854775807) (NegativeSignedRatioNotRepresentable str num den Int64 9223372036854775808 9223372036854775807 :: Constraint)) => CheckedNegativeRationalLiteral str num den (Ratio Int64) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 128) (NegativeSignedRatioNotRepresentable str num den Int8 128 127 :: Constraint), Assert (den <=? 127) (NegativeSignedRatioNotRepresentable str num den Int8 128 127 :: Constraint)) => CheckedNegativeRationalLiteral str num den (Ratio Int8) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeUnsignedRatioNotRepresentable str num den Word16 65535 :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Word16) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeUnsignedRatioNotRepresentable str num den Word32 4294967295 :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Word32) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeUnsignedRatioNotRepresentable str num den Word64 18446744073709551615 :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Word64) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeUnsignedRatioNotRepresentable str num den Word8 255 :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Word8) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeNaturalRatioNotRepresentable str num den Natural :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Natural) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(Assert (num <=? 9223372036854775808) (NegativeSignedRatioNotRepresentable str num den Int 9223372036854775808 9223372036854775807 :: Constraint), Assert (den <=? 9223372036854775807) (NegativeSignedRatioNotRepresentable str num den Int 9223372036854775808 9223372036854775807 :: Constraint)) => CheckedNegativeRationalLiteral str num den (Ratio Int) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

(NegativeUnsignedRatioNotRepresentable str num den Word 18446744073709551615 :: Constraint) => CheckedNegativeRationalLiteral str num den (Ratio Word) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * res) den <=? 0) (FixedRoundingError str (Fixed res) res :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed res) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1) den <=? 0) (FixedRoundingError str (Fixed E0) 1 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E0) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 10) den <=? 0) (FixedRoundingError str (Fixed E1) 10 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E1) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 100) den <=? 0) (FixedRoundingError str (Fixed E2) 100 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E2) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000) den <=? 0) (FixedRoundingError str (Fixed E3) 1000 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E3) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000000) den <=? 0) (FixedRoundingError str (Fixed E6) 1000000 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E6) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

Assert (Mod (num * 1000000000) den <=? 0) (FixedRoundingError str (Fixed E9) 1000000000 :: Constraint) => CheckedNegativeRationalLiteral str num den (Fixed E9) Source # 
Instance details

Defined in CheckedLiterals.Class.Rational

checkedNegativeRationalLiteral :: forall (fixed :: Symbol) (num :: Nat) (den :: Nat) a. CheckedNegativeRationalLiteral fixed num den a => a -> a Source #

Identity helper that attaches a negative rational literal check.

type PositiveUnsignedRatioNotRepresentable (str :: Symbol) (num :: t) (den :: t1) (typ :: t2) (maxVal :: t3) = TypeError (((((((((((('Text "Literal " ':<>: 'Text str) ':<>: 'Text " (") ':<>: 'ShowType num) ':<>: 'Text " % ") ':<>: 'ShowType den) ':<>: 'Text ")") ':<>: 'Text " cannot be represented by ") ':<>: 'ShowType typ) ':<>: 'Text ".") ':$$: (('Text "Make sure both the numerator and the denominator fit " ':<>: 'ShowType typ) ':<>: 'Text ".")) ':$$: ((('ShowType typ ':<>: 'Text " has bounds: [0 .. ") ':<>: 'ShowType maxVal) ':<>: 'Text "].")) ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #

type PositiveSignedRatioNotRepresentable (str :: Symbol) (num :: t) (den :: t1) (typ :: t2) (minVal :: t3) (maxVal :: t4) = TypeError (((((((((((('Text "Literal " ':<>: 'Text str) ':<>: 'Text " (") ':<>: 'ShowType num) ':<>: 'Text " % ") ':<>: 'ShowType den) ':<>: 'Text ")") ':<>: 'Text " cannot be represented by ") ':<>: 'ShowType typ) ':<>: 'Text ".") ':$$: (('Text "Make sure both the numerator and the denominator fit " ':<>: 'ShowType typ) ':<>: 'Text ".")) ':$$: ((((('ShowType typ ':<>: 'Text " has bounds: [-") ':<>: 'ShowType minVal) ':<>: 'Text " .. ") ':<>: 'ShowType maxVal) ':<>: 'Text "].")) ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #

type NegativeNaturalRatioNotRepresentable (str :: Symbol) (num :: t) (den :: t1) typ = TypeError ((((((((((('Text "Literal " ':<>: 'Text str) ':<>: 'Text " (-") ':<>: 'ShowType num) ':<>: 'Text " % ") ':<>: 'ShowType den) ':<>: 'Text ")") ':<>: 'Text " cannot be represented by ") ':<>: 'ShowType (Ratio typ)) ':<>: 'Text ".") ':$$: ('ShowType typ ':<>: 'Text " has bounds: [0 .. \8734].")) ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #

type NegativeUnsignedRatioNotRepresentable (str :: Symbol) (num :: k1) (den :: k2) typ (maxVal :: k3) = TypeError (((((('Text "Literal " ':<>: 'Text str) ':<>: 'Text " cannot be represented by ") ':<>: 'ShowType (Ratio typ)) ':<>: 'Text ".") ':$$: ('ShowType typ ':<>: 'Text " cannot represent negative numbers.")) ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #

type NegativeSignedRatioNotRepresentable (str :: Symbol) (num :: t) (den :: t1) (typ :: t2) (minVal :: t3) (maxVal :: t4) = TypeError (((((((((((('Text "Literal " ':<>: 'Text str) ':<>: 'Text " (-") ':<>: 'ShowType num) ':<>: 'Text " % ") ':<>: 'ShowType den) ':<>: 'Text ")") ':<>: 'Text " cannot be represented by ") ':<>: 'ShowType typ) ':<>: 'Text ".") ':$$: (('Text "Make sure both the numerator and the denominator fit " ':<>: 'ShowType typ) ':<>: 'Text ".")) ':$$: ((((('ShowType typ ':<>: 'Text " has bounds: [-") ':<>: 'ShowType minVal) ':<>: 'Text " .. ") ':<>: 'ShowType maxVal) ':<>: 'Text "].")) ':$$: 'Text "Possible fix: use 'uncheckedLiteral' from 'CheckedLiterals' to bypass this check.") :: k Source #