0
votes

This is my code, and it keeps giving me unbound error message.

I'm actually really new to SML. so, i really dont know how to fix it.

It seems like using a and b is bad thing.

I tried to declare a and b

like this

a : int;
b : int;

but still doesn't work.

How can i fix this?

2
Please post your code rather than linking to it. - John Coleman
Please don't post, or link to, pictures of text. Our ancestors gave us copy and paste. Learn how to use it. - molbdnilo

2 Answers

1
votes

It's just a syntax problem. All your code is missing is a | to separate the clauses of calculate. Just add one at the beginning of lines 5-8.

1
votes

Besides the missing |s between function clauses that Andreas mentions, you cannot apply the +, -, * and div operators to values of type calctree. You need to reduce each a and b to integers using your function first. For example,

datatype ops = PLUS | MINUS | TIMES | DIV
datatype calctree = LEAF of int | CALC of ops * calctree * calctree

fun getOp PLUS = op +
  | getOp MINUS = op -
  | getOp TIMES = op *
  | getOp DIV = op div

fun calc (LEAF x) = x
  | calc (CALC (oper, a, b)) = getOp oper (calc a, calc b)