【问题标题】:Why do I have unexpected '#' in the output for this code?为什么此代码的输出中有意外的“#”?
【发布时间】:2013-04-14 22:10:30
【问题描述】:

我正在尝试创建一个派生函数来区分 使用如下数据类型:

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))

为什么输出中有一个“#”?

任何帮助将不胜感激!

【问题讨论】:

标签: sml smlnj


【解决方案1】:

SML/NJ 对打印到控制台的深度结构有限制。如果达到此限制,则使用# 表示结构更大,但未显示。

如果您认为限制太低,您可以通过将Control.Print.printDepth 中存储的值更新为更适合您的值来进行更改。

Standard ML of New Jersey v110.69 [built: Mon Jun  8 14:15:08 2009]

- datatype 'a ls = Nil | Cons of 'a * 'a ls;
datatype 'a ls = Cons of 'a * 'a ls | Nil

- Cons(1, Cons(2, Cons(3, Cons(4, Nil))));
val it = Cons (1,Cons (2,Cons #)) : int ls

- Control.Print.printDepth;
val it = ref 5 : int ref

- Control.Print.printDepth := 100;
val it = () : unit

- Cons(1, Cons(2, Cons(3, Cons(4, Nil))));
val it = Cons (1,Cons (2,Cons (3,Cons (4,Nil)))) : int ls

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 2016-09-16
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多