我正在尝试创建一个派生函数来区分使用数据类型,如下所示:
datatype Symex = RCOEFF of real
| COEFF of string
| VAR of string
| POWER of Symex * int
| NEG of Symex
| PLUS of Symex * Symex
| MINUS of Symex * Symex
| MULT of Symex * Symex
| DIVIDE of Symex * Symex
这是 a*x^3 + 4.0*x^2 +b*x +c 的示例
PLUS (MULT (COEFF ("a"),
POWER (VAR ("x"), 3)),
PLUS (MULT (RCOEFF (4.0),
POWER (VAR ("x"), 2)),
PLUS (MULT (COEFF ("b"),
VAR ("x")),
COEFF ("c"))))
我的代码的一部分是
fun deriv (POWER(a, b)) = MULT(RCOEFF(Real.fromInt(b)), POWER(a, b-1))
但是当我计算
deriv(POWER(VAR "x", 3))
输出是
MULT(RCOEFF 3.0 , POWER(VAR # , 3))
为什么输出中有一个“#”?
请任何帮助将不胜感激!