我在标准 ML 中有以下代码:
datatype a = a;
val x = a;
val y:a = a;
val z = a;
fun fa a = a;
fun not' x = case x of
true => false
| false => true;
fun fst (a,b) = a;
fun snd (a,b) = b;
我在 sum 类型 ( not'
) 上的函数工作得很好,但是当我尝试在产品类型 ( fst
) 上使用我的函数时,它给了我这个错误:
- fst (1,2);
! Toplevel input:
! fst (1,2);
! ^
! Type clash: expression of type
! int
! cannot have type
! a
-
为什么?