RefinementTypes.FirstOrder
First-Order Types (§3.4)
A type is first-order if its values can be compared for equality.
Fixpoint fo (T: Ty) : bool :=
match T with
| TUnit ⇒ true
| TBool ⇒ true
| TInt32 ⇒ true
| TRefine A _ ⇒ fo A
| TMuAll _ ⇒ false
| _ ⇒ false
end.
match T with
| TUnit ⇒ true
| TBool ⇒ true
| TInt32 ⇒ true
| TRefine A _ ⇒ fo A
| TMuAll _ ⇒ false
| _ ⇒ false
end.
A type is ordered if its values support comparison (<, <=, >=, >).
Fixpoint ordered (T: Ty) : bool :=
match T with
| TInt32 ⇒ true
| TRefine A _ ⇒ ordered A
| _ ⇒ false
end.
match T with
| TInt32 ⇒ true
| TRefine A _ ⇒ ordered A
| _ ⇒ false
end.
A type is boolean if its values support logical operations (&&, ||).
Fixpoint bool_ty (T: Ty) : bool :=
match T with
| TBool ⇒ true
| TRefine A _ ⇒ bool_ty A
| _ ⇒ false
end.
match T with
| TBool ⇒ true
| TRefine A _ ⇒ bool_ty A
| _ ⇒ false
end.
Strip refinements to get the underlying base type.
Type-level compatibility for binary operations.
Definition bin_op_ty_compat (op: BinOp) (T: Ty) : bool :=
match op with
| OpEq | OpNeq ⇒ fo T
| OpLt | OpLe | OpGe | OpGt | OpAdd | OpSub | OpMul | OpDiv | OpMod ⇒ ordered T
| OpAnd | OpOr ⇒ bool_ty T
end.
match op with
| OpEq | OpNeq ⇒ fo T
| OpLt | OpLe | OpGe | OpGt | OpAdd | OpSub | OpMul | OpDiv | OpMod ⇒ ordered T
| OpAnd | OpOr ⇒ bool_ty T
end.
Result type of a binary operation.