KVV
KVV

Reputation: 61

Why do I have unexpected '#' in the output for this code?

I am trying to create a deriv function to differentiate using a datatype as follows:

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

here is an example for 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"))))

a part of my code is

fun deriv (POWER(a, b)) = MULT(RCOEFF(Real.fromInt(b)), POWER(a, b-1))

but when i calculate

deriv(POWER(VAR "x", 3))

the output is

MULT(RCOEFF 3.0 , POWER(VAR # , 3))

why is there a '#' in the output?

Please any help would be appreciated!!

Upvotes: 3

Views: 95

Answers (1)

SML/NJ has a limit on how deep structures are printed to the console. If this limit is reached, a # is used to signify, that the structure is larger, but not shown.

If you think the limit is too low, you can change it by updating the value stored in Control.Print.printDepth to a value that suits you better.

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

Upvotes: 6

Related Questions