12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849(* This file is free software, part of dolmen. See file "LICENSE" for more information *)moduleE=Dolmen.Std.ExprexceptionUnsupported_coercionofE.Ty.t*E.Ty.t(* Arithmetic conversions *)(* ************************************************************************* *)letcst=E.Term.Const.coerceletint_to_rat=letv=Fun.fun_1~cst(funv->letz=Value.extract_exn~ops:Int.opsvinRat.mk(Q.of_bigintz))in[E.Ty.int;E.Ty.rat],(fun_->v)letint_to_real=letv=Fun.fun_1~cst(funv->letz=Value.extract_exn~ops:Int.opsvinReal.mk(Q.of_bigintz))in[E.Ty.int;E.Ty.real],(fun_->v)letfallback=leta=E.Ty.Var.mk"a"inletb=E.Ty.Var.mk"b"in[E.Ty.of_vara;E.Ty.of_varb],(funsubst->leta_ty=E.Subst.Var.getasubstinletb_ty=E.Subst.Var.getbsubstinraise(Unsupported_coercion(a_ty,b_ty)))(* Builtins *)(* ************************************************************************* *)letbuiltins~eval:__env(cst:E.Term.Const.t)=matchcst.builtinwith|Dolmen.Std.Builtin.Coercion->Some(Fun.mk_clos@@Fun.ad_hoc~cst~ty_arity:2~arity:1[int_to_rat;int_to_real;fallback;])|_->None