Last active
August 29, 2015 14:00
-
-
Save sellout/11119737 to your computer and use it in GitHub Desktop.
How can I define Ord for integralTy?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
integralTy : (signed : Bool) -> Nat -> Type | |
integralTy False 0 = Bits8 | |
integralTy False 1 = Bits16 | |
integralTy False 2 = Bits32 | |
integralTy False 3 = Bits64 | |
integralTy _ _ = Integer | |
inRange : Ord (integralTy m n) => integralTy m n -> integralTy m n -> integralTy m n -> Bool | |
inRange x lower upper = lower <= x && x < upper | |
||| An integer in the range [lower, upper). BoundedInt 0 ~= Fin, but using | |
||| Integers instead of Peano arithmetic, for efficiency. Suitably limited | |
||| values (anything that doesn’t overflow [0–2^64)) use primitive machine types | |
||| instead of Integer. | |
BoundedInt : Integer -> Nat -> Type | |
BoundedInt lower upper = | |
(x : integralTy (lower < 0) (log2 upper) ** so (inRange x lower upper)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment