1

I have list in SML, which contains members from datatype "expr" (list "b"). I also have function "What", which it's arguments are only from dayatype "expr". Now I have problem in the next code:

datatype expr = K of string| Number2 of expr * (expr list);
datatype number = Number1 of string | Number3 of int;
What....
| What (Number2 (t,[]))= Number3(0)::What(t)
| What (Number2 (y,(a::b)) = append (What(a), What(b));

The error occurred because b is list of expr, and the function What got only "expr" and not "expr list". All I want to do is to check all the members is "b", and make a new list - which member is from datatype "number". I tried to use map function, but it didn't help (see the marks here: SML - unbound variable or constructor).

Any idea? There is another way to do it, without using map? I stack on it for a day..

Community
  • 1
  • 1
Adam Sh
  • 8,137
  • 22
  • 60
  • 75
  • You have to explain what you mean by "it didn't help", given the solution you got in the other question. It is not at all clear what you expect as correct output. Give the full definition of the `What` function and an example of input and expected output. – Jesper.Reenberg Nov 05 '11 at 11:10
  • 1
    Also note that instead of using your `append` function you could use the builtin function `@`. That would be `lst1 @ lst2`. – Jesper.Reenberg Nov 05 '11 at 11:13
  • @Jesper.Reenberg: Thanks a lot! the operator @ solve the problem! – Adam Sh Nov 05 '11 at 11:26

1 Answers1

9

For the sake of getting the question closed.

The append function you made in the previous question:

fun append (nil, l2) = l2 
  | append (x::xs, l2) = x::append(xs, l2);

can be replaced with the built in append operator @. As the documentation describes:

l1 @ l2
    returns the list that is the concatenation of l1 and l2. 
Jesper.Reenberg
  • 5,944
  • 23
  • 31