Skip to content

Instantly share code, notes, and snippets.

@sellout
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sellout/11119737 to your computer and use it in GitHub Desktop.
Save sellout/11119737 to your computer and use it in GitHub Desktop.
How can I define Ord for integralTy?
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