SML 中的通配符
Wild cards in SML
1 fun max(a,b,c) =
2 if a > b andalso a > c then a
3 else if b > a andalso b > c then b
4 else c
5
6
6 val x = max(1,_,3);
我用 SML 写了一个取三个数的 max 函数。如果我输入 3 个整数,它就可以正常工作。但是,如果我给函数一个通配符,它会抛出以下异常:max.sml:6.15 Error: syntax error: replacing WILD with EQUALOP
这是为什么?
通配符仅用于模式匹配。它们不能用作表达式,因为它们不会计算出值。
1 fun max(a,b,c) =
2 if a > b andalso a > c then a
3 else if b > a andalso b > c then b
4 else c
5
6
6 val x = max(1,_,3);
我用 SML 写了一个取三个数的 max 函数。如果我输入 3 个整数,它就可以正常工作。但是,如果我给函数一个通配符,它会抛出以下异常:max.sml:6.15 Error: syntax error: replacing WILD with EQUALOP
这是为什么?
通配符仅用于模式匹配。它们不能用作表达式,因为它们不会计算出值。