extern praxi 和 extern castfn 在表现力上有什么区别吗?
Is there any difference in expressiveness between an extern praxi and an extern castfn?
考虑:
#include "share/atspre_staload.hats"
fun only_zero(n: int(0)): void =
println!("This is definitely zero: ", n)
fun less_than{n,m:int | n < m}(n: int(n), m: int(m)): void =
println!(n, " is less than ", m)
implement main0() = (
only_zero(zeroify(n));
only_zero(m);
less_than(b, a);
less_than(f, e) where { val (f, e) = make_less_than((d, c)) };
) where {
val n = 5
val m = ~5
val (a, b, c, d) = (1, 2, 3, 4)
extern castfn zeroify{n:int}(n: int(n)): int(0)
extern praxi lemma_this_is_zero{n:int}(n: int(n)): [n == 0] void
extern castfn make_less_than{n,m:int}(t: (int(n), int(m))): [o,p:int | o < p] (int(o), int(p))
extern praxi lemma_less_than{n,m:int}(n: int(n), m: int(m)): [n < m] void
prval _ = lemma_this_is_zero(m)
}
它有这个输出:
This is definitely zero: 5
This is definitely zero: -5
2 is less than 1
4 is less than 3
是否存在需要其中之一而不是另一个的情况?
如果使用'castfn',您需要确保在目标语言中有相应的implicit转换函数。例如,如果 C 是目标语言,则 int2double 是一个 castfn。
另一方面,praxi/prfun被完全擦除,在生成的代码中没有任何痕迹。
我会说 praxi/prfun 更笼统,但 int2double 绝对不是 praxi/prfun。
考虑:
#include "share/atspre_staload.hats"
fun only_zero(n: int(0)): void =
println!("This is definitely zero: ", n)
fun less_than{n,m:int | n < m}(n: int(n), m: int(m)): void =
println!(n, " is less than ", m)
implement main0() = (
only_zero(zeroify(n));
only_zero(m);
less_than(b, a);
less_than(f, e) where { val (f, e) = make_less_than((d, c)) };
) where {
val n = 5
val m = ~5
val (a, b, c, d) = (1, 2, 3, 4)
extern castfn zeroify{n:int}(n: int(n)): int(0)
extern praxi lemma_this_is_zero{n:int}(n: int(n)): [n == 0] void
extern castfn make_less_than{n,m:int}(t: (int(n), int(m))): [o,p:int | o < p] (int(o), int(p))
extern praxi lemma_less_than{n,m:int}(n: int(n), m: int(m)): [n < m] void
prval _ = lemma_this_is_zero(m)
}
它有这个输出:
This is definitely zero: 5
This is definitely zero: -5
2 is less than 1
4 is less than 3
是否存在需要其中之一而不是另一个的情况?
如果使用'castfn',您需要确保在目标语言中有相应的implicit转换函数。例如,如果 C 是目标语言,则 int2double 是一个 castfn。
另一方面,praxi/prfun被完全擦除,在生成的代码中没有任何痕迹。
我会说 praxi/prfun 更笼统,但 int2double 绝对不是 praxi/prfun。